Tho*_*hoe 13 firebase google-cloud-functions firebase-storage
我正在尝试使用file.getSignedUrl()通过Google Cloud Functions(Nodejs)从Firebase Storage获取下载URL.我在Cloud Functions控制台中收到此错误:
{ 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' }
Run Code Online (Sandbox Code Playgroud)
我将代码从添加Firebase Admin SDK复制到您的服务器文档中.serviceAccountKey.json我的functions文件夹里有我的.firebase deploy没有给我错误
Error parsing triggers: Cannot find module 'serviceAccountKey.json'
Run Code Online (Sandbox Code Playgroud)
所以我必须走正确的道路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);
})
Run Code Online (Sandbox Code Playgroud)
我看到Doug Stevenson的答案有不同的代码,但它似乎等同于文档中的代码.
Tho*_*hoe 51
答案与云身份和访问管理有关.首先,转到您的Google Cloud Platform IAM和管理页面.你会看到各种服务帐户.查找看起来像的服务帐户myapp-cd99d@appspot.gserviceaccount.com.它应该App Engine default service account在Name专栏中说.(如果错误消息引用了其他服务帐户,请找到该服务帐户.)
在该Role列中,您可能会看到或不看到某些角色.如果您收到SigningError消息,该Role列将缺少角色服务帐户令牌创建者.选中左侧的复选框以myapp-cd99d@appspot.gserviceaccount.com选择服务帐户,然后单击右侧的铅笔进行编辑.在下一个屏幕中,单击+ADD ANOTHER ROLE.向下滚动Service Accounts,选择Service Account Token Creator并保存.现在您应该Service Account Token Creator在Roles列中看到App Engine default service account.现在您有权创建签名的令牌.
接下来,重复这些步骤并为其添加角色Storage Object Creator.这将允许您运行getSignedURL().
您可以另外保存服务帐户管理员和存储管理员,分别包括Service Account Token Creator和Storage Object Creator角色以及其他角色.
现在,如果你收到了一条SingingError消息,那可能是因为你在布鲁斯斯普林斯汀的"光荣日子"格格不入.:-)
就我而言,我启用了身份和访问管理 (IAM),网址如下:
https://console.developers.google.com/apis/api/iam.googleapis.com/overview?project= “您的项目名称”
| 归档时间: |
|
| 查看次数: |
2534 次 |
| 最近记录: |