Work in Progress
Firebase Admin SDK for Golang
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()
// ...
}
userID := "12345678"
claims := map[string]interface{}{"isAdmin": true}
token, err := firAuth.CreateCustomToken(userID, claims)
idToken := "ID_TOKEN_FROM_CLIENT"
claims, err := firAuth.VerifyIDToken(idToken)
if err != nil {
panic(err)
}
userID := claims.UserID
log.Println(userID)
user, err := firAuth.GetAccountInfoByUID("123312121")
users, err := firAuth.GetAccountInfoByUIDs([]string{"123312121", "2433232", "12121211"})
user, err := firAuth.GetAccountInfoByEmail("abc@gmail.com")
users, err := firAuth.GetAccountInfoByEmails([]string{"abc@gmail.com", "qqq@hotmail.com", "aaaqaq@aaa.com"})
err := firAuth.DeleteAccount("USER_ID")
userID, err := firApp.CreateAccount(&admin.Account{
Email: "aaa@bbb.com",
EmailVerified: true,
Password: "12345678",
DisplayName: "AAA BBB",
})
cursor := firApp.ListAccount(100)
for {
users, err := cursor.Next()
if users == nil || err != nil {
break
}
log.Println(len(users))
}
err := firApp.UpdateAccount(&UpdateAccount{
LocalID: "12121212",
Email: "new_email@email.com",
Password: "new_password",
DisplayName: "new name",
})