Firebase身份validationID令牌具有不正确的“审核”声明

我试图validation一个idToken后端。 用户已成功login到Firebase客户端,但是当我尝试validation我的后端idToken时,我得到这不是很有帮助的错误信息

Firebase身份validationID令牌具有不正确的“审核”声明

错误消息似乎已经变得更具信息性,并且归结为在validation密钥中没有项目名称:

错误:Firebase ID令牌具有不正确的“审核”(受众)声明。 预计“stripmall-0000”,但得到“617699194096-0aafcvsml0gke61d6077kkark051f3e1.apps.googleusercontent.com”。 确保ID令牌来自与用于validation此SDK的服务帐户相同的Firebase项目。 有关如何检索ID令牌的详细信息,请参阅https://firebase.google.com/docs/auth/server/verify-id-tokens 。

任何人有丝毫的想法可能是错的? 我从客户端正确接收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' }); }); 

您的问题可能是您正尝试使用其中一个auth()函数返回的JWT令牌,如firebaseRef.auth()。signInWithPopup()。 这些返回一个JWT令牌,但是authentication声明可能是错误的,不会通过verifyIdTokenvalidation。 这得到了firebase技术支持的证实。

你必须使用firebaseRef.auth()。currentUser.getToken()函数。 该令牌将通过validation。