首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >响应本机google登录防火墙无效令牌

响应本机google登录防火墙无效令牌
EN

Stack Overflow用户
提问于 2019-08-28 11:33:33
回答 2查看 1.7K关注 0票数 1

固定:所以我从react-native-google-signin收到的令牌是不够的,我还应该安装firebase并使用它,如所接受的答案所示,然后使用来自firebase的令牌。

原文:

我正在使用react-native-google-signin登录用户到一个应用程序,在登录时,我得到一个jwt令牌。

在firebase上,我有以下https云函数:

代码语言:javascript
运行
复制
exports.verify = functions.https.onRequest((req, res) => {
  const tokenId = req.get('Authorization').split('Bearer ')[1];
  return admin.auth().verifyIdToken(tokenId)
    .then((decoded) => res.status(200).send(decoded))
    .catch((err) => res.status(401).send(err));
});

当我从react-native-google-signin发送令牌进行验证时,我会得到以下响应:

代码语言:javascript
运行
复制
{
    "code": "auth/argument-error",
    "message": "Firebase ID token has incorrect \"aud\" (audience) claim. Expected \"my-project\" but got \"1232345345-sdfsdfsdfsdf.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/admin/verify-id-tokens for details on how to retrieve an ID token."
}

在这种情况下,aud是“my”身份验证方法中来自firebase google签名的webclient。我该如何解决这个问题,因为它是火焰基,给我的是令牌,它是拒绝令牌的火力基地.

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-08-29 03:36:01

首先,确保用于承载云功能的Firebase项目与React应用程序中使用的Firebase项目相同。

其次,确保在React应用程序中检索Firebase用户,然后调用getIdToken

示例

代码语言:javascript
运行
复制
import { GoogleSignin } from 'react-native-google-signin';

onLoginOrRegister = () => {
  GoogleSignin.signIn()
    .then((data) => {
      const credential = firebase.auth.GoogleAuthProvider.credential(data.idToken, data.accessToken);
      return firebase.auth().signInWithCredential(credential);
    })
    .then((user) => {

      // ** Now that the user is signed in, you can get the ID Token. **

      user.getIdToken(/* forceRefresh */ true).then(function(idToken) ... 

    })
    .catch((error) => {
      const { code, message } = error;
    });
}
firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken)
票数 3
EN

Stack Overflow用户

发布于 2021-10-15 11:42:05

我认为您是在Google SignIn之后使用令牌,其AUD与1232345345-sdfsdfsdfsdf.apps.googleusercontent.com类似。

调用signInWithCredential后,需要使用返回的令牌

谁的澳元将是您的project_id

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57691452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档