Expo, Firebase, Login with google

佐手、 提交于 2019-12-08 07:12:37

问题


in my React Native Expo application, I want to authenticate the user with google account. so I followed the Expo Googlefor a normal sign in with google first, Which was working, then using the idToken and accessToken to authenticate with 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 };
    }
  };

but I get the following error:

[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."}}]

回答1:


Add url in error message => eg. your case = 268165840544-097g31a3qhd0mm.apps.googleusercontent.com

under

Authentication > Sign-in Method > Google

Whitelist client IDs from external projects (optional) on Firebase



来源:https://stackoverflow.com/questions/49228826/expo-firebase-login-with-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!