【问题标题】:Error on firebase admin nodejs Permission iam.serviceAccounts.signBlob is requiredfirebase admin nodejs 上的错误需要权限 iam.serviceAccounts.signBlob
【发布时间】:2020-06-27 10:53:36
【问题描述】:

我正在使用本教程: https://firebase.google.com/docs/auth/admin/create-custom-tokens#using_a_service_account_id

创建一个 node.js 函数(部署到谷歌云函数)来验证我的用户。功能超级简单:

const admin = require('firebase-admin');
admin.initializeApp({
   serviceAccountId: 'authenticator@igibo-b0b27.iam.gserviceaccount.com'
});


exports.authenticate = (req, res) => {
   let pass;
   let uid;
   if (req.query) {
      if (req.query.v == 3) {
         pass = req.query.p;
         uid = req.query.u;
      }

         admin.auth().createCustomToken(uid)
            .then(function(customToken) {
               res.status(200).send(customToken);
               return customToken;
            })
            .catch(function(error) {
               console.error("Error creating custom token:" + JSON.stringify(error));
               res.status(400).send(error);
            });

   } else {
      console.error("EMPTY to authentication");
      res.end();
   }
};

但我遇到了这个烦人的错误:

{"code":"auth/insufficient-permission","message":"Permission iam.serviceAccounts.signBlob is required to perform this operation on service account projects/-/serviceAccounts/authenticator@igibo-b0b27.iam.gserviceaccount.com.; Please refer to https://firebase.google.com/docs/auth/admin/create-custom-tokens for more details on how to use and troubleshoot this feature."}

在同一个教程中,它说我必须去 IAM 并为我所做的服务帐户调整一些角色,但仍然出现此错误。

这是一个绝对简单的任务,不应该这么麻烦...... 我忘记了什么? id是对的!角色正确!代码是正确的!

怎么了?

【问题讨论】:

  • 您是否已将令牌创建者角色授予默认服务帐户?请注意,文档状态为Moreover, you must also make sure that the service account the Admin SDK is using to make this call —usually {project-name}@appspot.gserviceaccount.com— has the iam.serviceAccounts.signBlob permission. 。这在 Cloud Functions 上运行时尤为重要。
  • 我面临着完全相同的问题。我的自定义服务帐户和默认的 firebase-adminsdk 帐户都具有 Service Account Token CreatorService Account User 的 IAM 角色。错误信息仍然是Permission iam.serviceAccounts.signBlob is required to perform this operation
  • 我面临着完全相同的问题。
  • 我也面临这个问题。一切似乎都是一样的。我不知道该怎么做。有这方面的更新吗?
  • @Hunor,有时谷歌需要时间来传播权限,如果你确定你做得对,请等待 12 小时再试一次,它可能会神奇地解决

标签: firebase firebase-authentication firebase-admin


【解决方案1】:

我花了大约 6 个小时寻找答案。 @Hiranya Jayathilaka 所说的对我有用。

此外,您还必须确保 Admin SDK 用于进行此调用的服务帐户(通常是 {project-name}@appspot.gserviceaccount.com)具有 iam.serviceAccounts.signBlob 权限

【讨论】:

    【解决方案2】:

    Firebase 在其文档中提到了此错误:

    https://firebase.google.com/docs/auth/admin/create-custom-tokens#failed_to_determine_service_account

    您必须通过 JSON 配置文件正确初始化您的应用程序。

    一个简单的解决方法是:

    1. 转到 https://console.cloud.google.com/iam-admin/iam?project=PROJECT_NAME
    2. 编辑您的默认服务帐户。
    3. 添加角色服务帐户 令牌创建者

    几分钟后,您的项目将能够创建签名令牌。

    【讨论】:

    • 这也解决了一些其他问题,因此请检查是否已启用其他类似错误。
    猜你喜欢
    • 1970-01-01
    • 2017-05-19
    • 2019-12-25
    • 2022-12-04
    • 1970-01-01
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    • 2018-12-25
    相关资源
    最近更新 更多