我的项目使用firebase auth和函数。我的数据库api是在不同的供应商那里。我需要以 "管理员 "的身份从函数中对数据库进行一些调用。我的服务器被设置成通过以下配置来验证firebase的jwt令牌(自定义验证,不能使用firebase admin)。
{
"type":"RS256",
"jwk_url":"https://www.googleapis.com/service_accounts/v1/jwk/[email protected]",
"audience":"<firebase-project-id>",
"issuer":"https://securetoken.google.com/<firebase-project-id>"
}
这样可以正确验证ID令牌,但是无法解析由以下人员创建的自定义令牌 admin.auth().createCustomToken
并出现以下错误。
无法验证JWT:JWSError JWSInvalidSignature。
因此,我不能使用自定义令牌来验证我的云功能,除非我能够以某种方式验证它们?
我的函数令牌是这样生成的。
const uid = "function-worker";
const claims = {
"https://hasura.io/jwt/claims": {
"x-hasura-default-role": "function",
"x-hasura-allowed-roles": ["function"],
"x-hasura-user-id": uid,
},
};
const jwt = await admin.auth().createCustomToken(uid, claims);
生成 jwt
然后发送到我的 哈苏拉 服务器按照 https:/github.comhasuragraphql-enginetreemastercommunitysample-appsfirebase-jwt。
按照上面的指南对id代币有效,但对自定义代币无效。更详细的说明 哈苏拉 服务器处理jwt验证可以在这里找到。https:/github.comhasuragraphql-engineblobdcab20a5ee388ebd754a7828de1309a3a2e0eaeedocsgraphqlmanualauthauthenticationjwt.rst#generating-jwt-config。
你可以使用Firebase REST API来生成一个id token,在服务器端。https:/firebase.google.comdocsreferencerestauth)。