小编Fau*_*tus的帖子

Firebase身份验证ID令牌具有错误的"aud"声明

我正在尝试验证idToken后端.用户已成功登录到firebase客户端,但当我尝试验证后端的idToken时,我得到的这个不是非常有用的错误消息

Firebase身份验证ID令牌具有错误的"aud"声明

错误消息似乎变得更有用,并归结为在auth密钥中没有项目名称:

错误:Firebase ID令牌具有错误的"aud"(受众群体)声明.预计"stripmall-0000"但得到"617699194096-0aafcvsml0gke61d6077kkark051f3e1.apps.googleusercontent.com".确保ID令牌来自与用于对此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'
        });

    });
Run Code Online (Sandbox Code Playgroud)

node.js firebase firebase-authentication

17
推荐指数
2
解决办法
4112
查看次数