firebase - Expo, Firebase, 使用谷歌登录

标签 firebase react-native firebase-authentication expo

在我的 React Native Expo 应用程序中,我想使用 google 帐户对用户进行身份验证。所以我跟着Expo Google首先使用 google 正常登录,这是有效的,然后使用 idTokenaccessToken 通过 firebase 进行身份验证。

  signInWithGoogleAsync = async () => {
    try {
      const result = await Google.logInAsync({androidClientId: ***, iosClientId: ***, scopes: ["profile", "email"] });

      if (result.type === "success") { // I get result object
        const credential = firebase.auth.GoogleAuthProvider.credential( result.idToken, result.accessToken);
        /* credential is and xf {} object */
        firebase.auth().signInWithCredential(credential)
          .then(user => {console.log( user);})
          .catch(error => {console.log(error);});
        return result.accessToken;
      }
      return { cancelled: true };
    } catch (e) {
      return { error: true };
    }
  };

但我收到以下错误:

[Error: {"error":{"errors":[{"domain":"global","reason":"invalid","message":"Invalid Idp Response: the Google id_token is not allowed to be used with this application. Its audience (OAuth 2.0 client ID) is 268165840544-097g31a3qhd0mm.apps.googleusercontent.com, which is not authorized to be used in the project with project_number: 747269174."}],"code":400,"message":"Invalid Idp Response: the Google id_token is not allowed to be used with this application. Its audience (OAuth 2.0 client ID) is 26816581eun236bp9vdb7b6r.apps.googleusercontent.com, which is not authorized to be used in the project with project_number: 747269174."}}]

最佳答案

在错误消息中添加 url => 例如。你的案例 = 268165840544-097g31a3qhd0mm.apps.googleusercontent.com

身份验证 > 登录方式 > Google

Firebase 上的外部项目白名单客户端 ID(可选)

关于firebase - Expo, Firebase, 使用谷歌登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49228826/

相关文章:

firebase - 从Cloud Firestore检索仅一个用户的文档,然后将其推送到Widget Flutter中

javascript - 如何检测用户是否已登录 Firebase?

android - 来自现有 GCM 项目的 GCM API key ?

java - 如何在纯Java(非Android)中订阅和接收Firebase消息

javascript - 通过不等式查询firestore

javascript - Firebase数据重复问题

javascript - 如何在 react native 渲染中以无限循环返回数组项 View ?

javascript - useSelector() 返回未定义

javascript - 基于多个 ScrollView(s) 为单个 View 设置动画

javascript - undefined 不是函数 this.setState