問題
以下のようなエラーがでる
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