im使用这个教程。https:/firebase.google.comdocsauthadmincreate-custom-tokens#using_a_service_account_id。
创建一个node.js函数(部署到谷歌云函数)来验证我的用户。这个函数超级简单。
const admin = require('firebase-admin');
admin.initializeApp({
serviceAccountId: '[email protected]'
});
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/[email protected].; 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是正确的!角色是正确的!代码是正确的!怎么了?
错在哪里?
Firebase在其文档中提到了这个错误。
https:/firebase.google.comdocsauthadmincreat-custom-tokens#failed_to_determine_service_account。
你必须通过JSON配置文件正确初始化你的应用程序。
一个简单的修复方法是
在几分钟内,你的项目将能够创建签名代币。