LoginSignup
1
2

More than 5 years have passed since last update.

カスタムトークン作成時のエラー:error minting custom token

Posted at

問題

以下のようなエラーがでる

error minting custom token: http error status: 403; reason: Identity and Access Management (IAM) API has not been used in project XXXXXXXXXXXX before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/iam.googleapis.com/overview?project=XXXXXXXXXXXX then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

動作環境

  • Google App Engine / SE
  • Go 1.9
  • Firebase Authentication

問題が出たコード

    conf := &firebase.Config{
        ServiceAccountID: "my-client-id@my-project-id.iam.gserviceaccount.com",
    }
    app, err := firebase.NewApp(ctx, conf)
    if err != nil {
        log.Errorf(ctx, "error initializing app: %v", err)
        return "", err
    }

解決法

該当のサービスアカウント(ここではGAEのデフォルトサービスアカウント)にiam.serviceAccounts.signBlobを付与。

・・・すれば解決するのだが、プロジェクトにて自分にIAMを設定する権限がなかったので、jsonを読む形で一時的に動した。

    opt := option.WithCredentialsFile("./xxxxxxxxxxx.json")
    app, err := firebase.NewApp(ctx, nil, opt)
    if err != nil {
        log.Errorf(ctx, "error initializing app: %v", err)
        return "", err
    }

参考

公式ドキュメント - カスタム トークンを作成する
https://firebase.google.com/docs/auth/admin/create-custom-tokens?hl=ja#before_you_begin

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2