私はidTokenバックエンドを検証しようとしています。ユーザーはfirebaseクライアント側に正常にログインしましたが、私は私のバックエンドでidTokenを検証しようとすると、私はこの非常に有用ではないエラーメッセージFirebase認証IDトークンに不正な "aud"クレームがあります
Firebase Auth ID token has incorrect "aud" claim
は、エラーメッセージがもう少し有益になっているようだ、と沸騰取得します認証キーにプロジェクト名が含まれていないことを確認してください:
Error: Firebase ID token has incorrect "aud" (audience) claim. Expected "stripmall-0000" but got "617699194096-0aafcvsml0gke61d6077kkark051f3e1.apps.googleusercontent.com". Make sure the ID token comes from the same Firebase project as the service account used to authenticate this SDK. See https://firebase.google.com/docs/auth/server/verify-id-tokens for details on how to retrieve an ID token.
何が間違っている可能性がありますか?私はクライアントから正しくtokenIdを受け取り、問題ではないはずです。これが以前に尋ねられたか、または他の方法で自明でない場合、誠実なappologies。
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ファイルからまっすぐに渡されたので、そのファイルに何か問題があると想像できません。 – Faustus
これも一貫して間違っています。それは、私の聴衆キーがすべきであるというさらなるメッセージを得る。 –