关于Firebase Admin SDK中的invalid_scope错误

时间:2019-11-09 23:39:24

标签: firebase go firebase-admin

我正在使用Go为Firebase admin sdk创建一个应用。
当我尝试获取Firebase用户时,发生以下错误。

我很麻烦。
如果您熟悉此错误,请帮助我解决该错误。

谢谢!

[代码]

func CreateAdministrator(c *gin.Context) error {
    test := os.Getenv("FIREBASE_KEY")
    data, _ := base64.StdEncoding.DecodeString(test)
    credentials, err := google.CredentialsFromJSON(c, data)
    if err != nil {
        log.Printf("error credentials from json: %v\n", err)
        os.Exit(1)
    }
    opt := option.WithCredentials(credentials)
    app, err := firebase.NewApp(c, nil, opt)
    if err != nil {
        log.Printf("error initializing app: %v\n", err)
    }
    client, err := app.Auth(c)
    if err != nil {
        fmt.Printf("error: %v\n", err)
        os.Exit(1)
    }
    uid := "1WIRrGcHmxZvy9ncJ9MZVNEdt5C3"
    u, err := client.GetUser(c, uid)
    if err != nil {
        log.Fatalf("error getting user %s: %v\n", uid, err)
    }
    log.Printf("Successfully fetched user data: %v\n", u)
    return err
}

[发生错误]

2019/11/10 08:19:26 error getting user 1WIRrGcHmxZvy9ncJ9MZVNEdt5C3: error while making http call: Post https://identitytoolkit.googleapis.com/v1/projects/・・・/accounts:lookup: oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_scope",
  "error_description": "Empty or missing scope not allowed."
}

0 个答案:

没有答案