0

My app has a Firebase based Google login. I am trying to get access Token but getting undefined.I am getting the idToken but I need AccessToken and refresh Tokens.I need help

Here is my code :

GoogleSignin.configure({
    scopes: ['profile', 'email','https://www.googleapis.com/auth/calendar'], //adding calender scope
      webClientId: '863338747777-9bshdpj951ga8nik9tbtua52ji0h06k4.apps.googleusercontent.com',
      offlineAccess: true,
      forceCodeForRefreshToken: true,
    });

const onGoogleButtonPress = async()=> {

   try
   {
    await GoogleSignin.hasPlayServices();
    const {accessToken, idToken} = await GoogleSignin.signIn();
    const credential = auth.GoogleAuthProvider.credential(
      idToken,
      accessToken,
    );
    await auth().signInWithCredential(credential);
    
          console.log('IDToken: ',idToken,accessToken)
          console.log('AccessToken: ',accessToken)
   }
    catch(error)
    {
      console.log(error)
    }
    finally{
      setLoggedIn(true)
    }    
  }`

2 Answers 2

1

I found a solution for my own problem. I am using a older library of React native google sign in. The new one is react native login google. The new package is returning the accessToken as well. So to get the refresh token we need to use a api This is the Link for that .

We need several headers Take a look at them

You will get the serverAuthCode from the googleSignin function while signing in .

const UserInfo = await GoogleSignin.signIn();

Console log the UserInfo to get the serverAuthCode ,AccessToken and Refresh Token

This is the Package I am using for googlesignIn

Sign up to request clarification or add additional context in comments.

Comments

0

Prabhakar I hope this link helpful for him.

https://www.freecodecamp.org/news/google-login-with-react-native-and-firebase/

Thank You

1 Comment

Thanks but this did'nt help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.