/go-firebase-admin

Unofficial Firebase Admin SDK for Golang

Primary LanguageGoMIT LicenseMIT

go-firebase-admin

Go Report Card GoDoc MIT Licence

Table of Contents

Overview

Firebase Admin SDK for Golang

On Wednesday, May 17, 2017 Google announced at Google IO : Open sourcing the Firebase SDKs. But for now, there is no official Admin SDK for Golang, only Java, Node and Python Admin SDKs.

So welcome go-firebase-admin SDK :)

Note

If you decide to use this unofficial SDK still in development, 
please use any package manager to fix version, there will be a lot of breaking changes.

Installation

Install the package with go:

go get github.com/acoshift/go-firebase-admin

Features

This go-firebase-admin SDK supports the following functions :

  • Authentication

  • User Management API

    • GetUser : fetching the profile information of users by their uid
    • GetUsers : fetching list of profile information of users by their uid
    • GetUserByEmail : fetching the profile information of users by their email
    • GetUsersByEmail : fetching list of profile information of users by their email
    • ListUsers : fetching the profile information of users
    • CreateUser : create a new Firebase Authentication user
    • UpdateUser : modifying an existing Firebase user's data.
    • DeleteUser : deleting existing Firebase user by uid
    • SendPasswordResetEmail : send password reset for the given user
    • VerifyPassword : verifies given email and password
  • Realtime Database API

    • not documented
  • Cloud Messaging API

    • SendToDevice : Send Message to individual device
    • SendToDevices : Send multicast Message to a list of devices
    • SendToDeviceGroup : Send Message to a device group
    • SendToTopic : Send Message to a topic
    • SendToCondition : Send a message to devices subscribed to the combination of topics
    • SubscribeDeviceToTopic : TODO
    • SubscribeDevicesToTopic : TODO
    • UnSubscribeDeviceFromTopic : TODO
    • UnSubscribeDevicesFromTopic : TODO

To-Do List

  • update documentation
  • add examples
  • add FCM

Documentation

You can find more details about go-firebase-admin on godoc.org.

Examples

You need a service_account.json file, if you don't have an admin SDK service_account.json, please [check this guide] (https://firebase.google.com/docs/admin/setup#add_firebase_to_your_app)

Initialize Firebase Admin SDK

package main

import (
  "io/ioutil"

  "github.com/acoshift/go-firebase-admin"
)

func main() {
  // Init App with service_account
  serviceAccount, _ := ioutil.ReadFile("service_account.json")
  firApp, err := admin.InitializeApp(context.Background(), admin.AppOptions{
    ServiceAccount: serviceAccount,
    ProjectID:      "YOUR_PROJECT_ID",
    DatabaseURL:    "YOUR_DATABASE_URL",
    APIKey:         "YOUR_API_KEY",
  })

  if err != nil {
    panic(err)
  }

  firAuth := firApp.Auth()
  firDatabase := firApp.Database()

  // FCM
  firFCM := firApp.FCM()

  resp, err := firFCM.SendToDevice("registrationToken", admin.Message{To: "toto"})
	if err != nil {
    panic(err)
	}
  
}

Licence

MIT License

Copyright (c) 2016 Thanatat Tamtan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.