Skip to content

8legd/go-firebase-admin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-firebase-admin

Go Report Card GoDoc

Work in Progress

Firebase Admin SDK for Golang

Usage

Init

package main

import (
  "io/ioutil"
  "log"

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

func main() {
  // Init App
  serviceAccount, _ := ioutil.ReadFile("service_account.json")
  firApp, err := admin.InitializeApp(admin.ProjectID("YOUR_PROJECT_ID"), admin.ServiceAccount(serviceAccount))
  if err != nil {
    panic(err)
  }
  firAuth := firApp.Auth()

  // ...
}

CreateCustomToken

userID := "12345678"
claims := map[string]interface{}{"isAdmin": true}
token, err := firAuth.CreateCustomToken(userID, claims)

VerifyIDToken

idToken := "ID_TOKEN_FROM_CLIENT"
claims, err := firAuth.VerifyIDToken(idToken)
if err != nil {
  panic(err)
}

userID := claims.UserID
log.Println(userID)

GetAccountInfoByUID

user, err := firAuth.GetAccountInfoByUID("123312121")

GetAccountInfoByUIDs

users, err := firAuth.GetAccountInfoByUIDs([]string{"123312121", "2433232", "12121211"})

GetAccountInfoByEmail

user, err := firAuth.GetAccountInfoByEmail("abc@gmail.com")

GetAccountInfoByEmails

users, err := firAuth.GetAccountInfoByEmails([]string{"abc@gmail.com", "qqq@hotmail.com", "aaaqaq@aaa.com"})

DeleteAccount

err := firAuth.DeleteAccount("USER_ID")

CreateAccount

userID, err := firApp.CreateAccount(&admin.Account{
  Email:         "aaa@bbb.com",
  EmailVerified: true,
  Password:      "12345678",
  DisplayName:   "AAA BBB",
})

ListAccount

cursor := firApp.ListAccount(100)
for {
  users, err := cursor.Next()
  if users == nil || err != nil {
    break
  }
  log.Println(len(users))
}

UpdateAccount

err := firApp.UpdateAccount(&UpdateAccount{
  LocalID: "12121212",
  Email: "new_email@email.com",
  Password: "new_password",
  DisplayName: "new name",
})

About

Unofficial Firebase Admin SDK for Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%