【发布时间】: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 Creator和Service Account User的 IAM 角色。错误信息仍然是Permission iam.serviceAccounts.signBlob is required to perform this operation -
我面临着完全相同的问题。
-
我也面临这个问题。一切似乎都是一样的。我不知道该怎么做。有这方面的更新吗?
-
@Hunor,有时谷歌需要时间来传播权限,如果你确定你做得对,请等待 12 小时再试一次,它可能会神奇地解决
标签: firebase firebase-authentication firebase-admin