代码之家  ›  专栏  ›  技术社区  ›  Thomas David Kehoe

Firebase getSignedUrl()的签名错误

  •  3
  • Thomas David Kehoe  · 技术社区  · 7 年前

    我想用 file.getSignedUrl() 通过谷歌云功能(Nodejs)从Firebase存储获取下载URL。我在云功能控制台中遇到此错误:

    { SigningError: A Forbidden error was returned while attempting to retrieve an access token for the Compute Engine built-in service account. This may be because the Compute Engine instance does not have the correct permission scopes specified. Permission iam.serviceAccounts.signBlob is required to perform this operation on service account projects/myapp-cd94d/serviceAccounts/myapp-cd94d@appspot.gserviceaccount.com.
        at SigningError (/user_code/node_modules/@google-cloud/storage/build/src/file.js:58:9)
        at authClient.sign.then.catch.err (/user_code/node_modules/@google-cloud/storage/build/src/file.js:1019:22)
        at process._tickDomainCallback (internal/process/next_tick.js:135:7) name: 'SigningError' }
    

    Add the Firebase Admin SDK to Your Server serviceAccountKey.json 在我的 functions firebase deploy 不是给了我错误吗

    Error parsing triggers: Cannot find module 'serviceAccountKey.json'
    

    因此,我必须有正确的道路,以我的 serviceAccountKey.json firebase-admin 6.1.0 firebase-tools 6.1.0

    const admin = require('firebase-admin');
    var serviceAccount = require("./myapp-cd94d-firebase-adminsdk-1234x-sEcReT.json");
    
    admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
      databaseURL: "https://myapp-cd94d.firebaseio.com"
    });
    
    ...
    
    const config = {
      action: 'read',
        expires: '03-17-2025'
      };
    
    file.getSignedUrl(config).then(function(data) {
        const url = data[0];
        console.log(url);
      })
      .catch(function(error) {
        console.error(error);
      })
    

    Doug Stevenson's answer 具有不同的代码,但似乎与文档中的代码相同。

    1 回复  |  直到 7 年前
        1
  •  107
  •   Thomas David Kehoe    7 年前

    答案与此有关 Cloud Identity and Access Management . 首先,进入你的谷歌云平台 IAM & admin 页你会看到各种各样的 服务帐户 myapp-cd99d@appspot.gserviceaccount.com . 应该说 App Engine default service account Name

    Role 列中,您可能会看到或看不到某些角色。如果你得到一个 SigningError 讯息 服务帐户令牌创建者 . 选中对话框左侧的复选框 myapp-cd99d@appspot.gserviceaccount.com 选择服务帐户,然后单击右侧的铅笔进行编辑。在下一个屏幕中,单击 +ADD ANOTHER ROLE . 向下滚动至 Service Accounts Service Account Token Creator ,然后保存。现在你应该明白了 Roles 专栏

    接下来,重复这些步骤并为添加角色 Storage Object Creator getSignedURL()

    您可以保存或分配服务帐户管理员和存储管理员,其中包括 服务帐户令牌创建者 存储对象创建者

    SingingError 信息,这可能是因为你在唱布鲁斯·斯普林斯汀的《荣耀的日子》走调了。:-)

        2
  •  3
  •   Pol Fernández    7 年前

    在我的例子中,我启用了身份和访问管理(IAM),url如下所示:

    https://console.developers.google.com/apis/api/iam.googleapis.com/overview?project=