How to authenticate in Firebase through Google using Expo (React Native)?

Asked

Viewed 304 times

0

I have a web application on firebase, but I’m using it in the development of an android/Ios app using Expo. I want the authentication to be done by Google, but it turns out that because it was created as a web, it asks for the client’s secret ID and key. The function is like this:

   async signInWithGoogleAsync() {
    try {
      const result = await Expo.Google.logInAsync({
        androidClientId: 'meuandroidID',
        iosClientId: 'meuIOSID',
        scopes: ['profile', 'email'],
      });

      if (result.type === 'success') {
        const { idToken, accessToken } = result;
        const credential = firebase.auth.GoogleAuthProvider.credential(idToken, accessToken);
        firebase
        .auth()
        .signInAndRetrieveDataWithCredential(credential)
        .then(res => {
          console.log(res)
        })
        .catch(error => {
          console.log("firebase cred err:", error);
        });
        // return result.accessToken;
      } else {
        // return { cancelled: true };
      }
    } catch (e) {
      // return { error: true };
    }
   }

So when the user authenticates, the ID sent is android or IOS, which returns the following error, saying that because it is not a web ID it is not allowed:

[Error: {"error":{"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 MYID, which is not authorized to be used in the project with project_number: MYPROJECTNUMBER.","errors":[{"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 MYID, which is not authorized to be used in the project with project_number: MYPROJECTNUMBER.","domain":"global","reason":"invalid"}]}}]

So, how do I solve this problem and get authenticated with Google on firebase Web using Expo React?

1 answer

0

I managed to solve, I did it this way:

inserir a descrição da imagem aqui

I simply added the ID’s there under "Add Client Ids to..."

Browser other questions tagged

You are not signed in. Login or sign up in order to post.