【发布时间】:2016-11-15 01:32:36
【问题描述】:
我正在尝试验证 idToken 后端。用户已成功登录到 Firebase 客户端,但是当我尝试在后端验证 idToken 时,我收到这个不是很有帮助的错误消息
Firebase Auth ID 令牌的“aud”声明不正确
错误消息似乎变得更加有用,归结为在 auth 键中没有项目名称:
错误:Firebase ID 令牌的“aud”(受众)声明不正确。 预期“stripmall-0000”但得到 “617699194096-0aafcvsml0gke61d6077kark051f3e1.apps.googleusercontent.com”。 确保 ID 令牌与 用于验证此 SDK 的服务帐户。看 https://firebase.google.com/docs/auth/server/verify-id-tokens 为 有关如何检索 ID 令牌的详细信息。
任何人都知道可能出了什么问题?我从客户端正确收到了 tokenId,所以这应该不是问题。如果以前有人问过这个问题或以任何其他方式微不足道,请真诚地道歉。
firebase.initializeApp({
serviceAccount: {
"type": "service_account",
"project_id": <project id here>,
"private_key_id": <key id goes here>,
"private_key": <key goes here>
"client_email": <email goes here>,
"client_id": <my client id>,
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": <url goes here>
},
databaseURL: <my db url here>
});
router.post("/verify", function (req, res) {
firebase.auth().verifyIdToken(req.body.idToken).then(function (decodedToken) {
var uid = decodedToken.sub;
res.send(uid);
}).catch(function (error, param2) {
console.log(error); // 'Firebase Auth ID token has incorrect "aud" claim'
});
});
【问题讨论】:
-
据我了解,
aud用于“受众”,在这种情况下指的是项目 ID。你确定那里有正确的 project_id 吗? -
嗯,它们是直接从你下载的 json 文件传递过来的,所以无法想象那个会有什么问题..
-
我也看到这一直是错误的。它会得到进一步的信息,我的受众密钥应该是什么。
标签: node.js firebase firebase-authentication