react-native-google-signin / google-signin

Google Sign-in for your React Native applications
https://react-native-google-signin.github.io/
MIT License
3.19k stars 879 forks source link

signInSilently gives error [Error: SIGN_IN_REQUIRED] #1244

Closed emmanuelfrancis closed 7 months ago

emmanuelfrancis commented 7 months ago

I tried calling signInSilently after successful signin but it return SIGN_IN_REQUIRED on Android.

Below are the steps and code:


const GOOGLE_SSO_CONFIG: {
        webClientId: 'id',
        offlineAccess: true,
        forceCodeForRefreshToken: true,
        iosClientId: 'id',
        profileImageSize: 120,
    },
GoogleSignin.configure(GOOGLE_SSO_CONFIG);
    const userInfo = await GoogleOneTapSignIn.signIn(
            GOOGLE_SSO_CONFIG,
        )
        .then(userInfo => {
            console.log('Google signin ' + JSON.stringify(userInfo));
        })
        .catch(e => {});

After successful login on a button click:
            try {
                console.debug('calling signInSilently ');
                const userInfoSilent = await GoogleSignin.signInSilently();
                console.log('userInfoSilent ' + userInfoSilent);
            } catch (error) {
                console.error('signInSilently ', error);
            }

Expected Behavior

It should return user object.

Actual Behavior

It returns an error [Error: SIGN_IN_REQUIRED] on Android. Please note that this works fine on iOS GoogleSignin.signIn

Environment

@react-native-google-signin/google-signin version 11.1.4 Android OS 14

vonovak commented 7 months ago

Hello and thanks for reporting, This issue is missing a lot of information, such as platform and reproducible code. It's not actionable at this point.

Thank you 🙂

emmanuelfrancis commented 7 months ago

@vonovak thanks for the quick reply. Sorry about not providing the details. I have just updated the details above. Could you please check and let me know if I am missing anything or if you would need more details.

Thanks alot.

vonovak commented 7 months ago

Hello, thanks for adding the details. There is a chance that I documented this incorrectly, I'll need to double check but it'll take some time. What is it that you're trying to achieve in the end?

Thank you

emmanuelfrancis commented 7 months ago

I am trying to do the following:

  1. The user successfully logged in using Google.
  2. After an hour Google idToken expires.
  3. When the user opens the app after an hour. I would like to get the new token, so I am thinking of calling GoogleSignin.signInSilently() to get the updated idToken.
  4. Not sure I would also require to call getTokens() to get the new idToken.
emmanuelfrancis commented 7 months ago

@vonovak I think I have to use serverAuthCode and refreshToken to get the idToken on the backend.

vonovak commented 7 months ago

Can you explain a little more, and at a higher-level what you want to do?

emmanuelfrancis commented 7 months ago

Can you check my previous message https://github.com/react-native-google-signin/google-signin/issues/1244#issuecomment-1941043941

Does that answer?

emmanuelfrancis commented 7 months ago

I think my problem is related to this https://github.com/react-native-google-signin/google-signin/issues/1100 that's why I said I would have to use serverAuthCode to get refreshToken on the backend and refresh the idToken using refreshToken on the backend not on the android app.

Or please let me know if there is any workaround on the module to get the updated "idtoken". Can this be done using signInSilently?

Thanks.