expo-auth-session/providers/google Android Standalone Issue

Hi Everyone
First off I have been scoring the web for answer and tried everything they suggested but nothing has resolved this aggravating issue

I’m using expo-auth-session/providers/google and on IOS it works perfectly but on Android I keep running up against this race issue that causes the google sign in to not redirect back to the app and default to a “response: dismiss”.

Can anyone point me to a reliable fix for this? Otherwise can anyone suggest a different library that will work on React-native & Expo that will get my google login to work?

This has been a long hard battle and I’m really stuck so any help would be awesome

On Expo SDK 48
Thanks

Hey @freem11,

I responded to your queries on the thread: Potential liability with instructions for Google Authentication - #11 by amanhimself

If you can share a minimal reproducible example, I’m happy to look into it.

Also, as @wodin suggested, you can try using the following library:

@amanhimself
Not sure if this is enough but here is all my code for this:

package.json:
“expo-application”: “~5.1.1”,
“expo-auth-session”: “~4.0.3”,
“expo-crypto”: “~12.2.1”,
“expo-web-browser”: “~12.1.1”

app.json:
“scheme”: [“com.divego”, “fbXXXXXXX”]

sign in page:
import * as WebBrowser from “expo-web-browser”;
import * as Google from “expo-auth-session/providers/google”;

WebBrowser.maybeCompleteAuthSession();

const googleExpoClientId = config.EXPO_CLIENT_ID;
const googleAndroidClientId = config.ANDROID_CLIENT_ID;
const googleIOSClientId = config.IOS_CLIENT_ID;
const facebookAppId = config.FACEBOOK_APP_ID;

export default function SignInRoute() {

const [req, res, promptAsync] = Google.useAuthRequest({
androidClientId: googleAndroidClientId,
iosClientId: googleIOSClientId,
expoClientId: googleExpoClientId,
});

useEffect(() => {
handleGoogleSignIn();
}, [res]);

async function handleGoogleSignIn() {
alert(“response?” + res.type)
if (res?.type === “success”) {
await getGoogleUserData(res.authentication.accessToken);
}
}

<TouchableWithoutFeedback
onPress={() => {promptAsync();
}}
disabled={!req}
>

      <View style={[styles.SignUpWithButtons]}>
        <Image source={googleLogo} style={[styles.gLogo]} />
        <Text
          style={{
            color: "#FFFFFF",
            fontFamily: "PermanentMarker_400Regular",
            fontSize: 12,
            opacity: 0.7,
          }}
        >
          Sign In With Google
        </Text>
      </View>
    </TouchableWithoutFeedback>

}

the alert always comes back with “response?dismiss”

again on IOS it works without any issue, but on Android standalone I’m always getting this result

I’d suggest removing expoClientId as its not required anymore since Proxy is deprecated with SDK 48. Also, are you creating a development build?

I have removed the expoClientId as you suggested

The latest build is still returning with response?dismiss

Regarding development builds. - npx expo run:ios. runs just fine
but
npx expo run:android is failing with:
1: Task failed with an exception.

  • Where:
    Script ‘/Users/matthewfreeman/dgmobile/frontend/DiveGoMobile/node_modules/expo-modules-autolinking/scripts/android/autolinking_implementation.gradle’ line: 326

  • What went wrong:
    A problem occurred evaluating project ‘:expo’.

A problem occurred configuring project ‘:expo-modules-core’.
Failed to notify project evaluation listener.
SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project’s local properties file at ‘/Users/matthewfreeman/dgmobile/frontend/DiveGoMobile/android/local.properties’.
Could not get unknown property ‘release’ for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.

So i have been doing build to the google play store to test, is there something you can recommend to sort out the Android build issue? I have tried a few suggestions online but maybe i just need to uninstall and reinstall expo and all the associated libraries? (if there is an easier way please share)

Thank you for you help so far by the way I do appreciate it, and this Android issue has been awful to deal with on my own.

From above, it seems that the ANDROID_HOME env variable is not set to the Android SDK directory that is created when you install Android Studio. React Native docs explain on how to do so: Setting up the development environment · React Native

You’ll have to check and make sure that is set correctly and then run npx expo run:android command again. This is not an Expo related issue.

whew ok had to fumble around a bit but got the Android Home issue resolved and npx expo run:android now build successfully, however, once built I tried the google sign in and got the same result as i was getting on google play testing selecting an account spins for a bit then goes to the google homepage instead of redirecting, sometimes it also does redirect, but the result is still no sign in and my alert for the response still comes up with “response?dismiss”

Is there any other info I can supply you with that could be helpful to resolve this auto dismiss that google keeps giving?

@amanhimself If there is nothing else I can send you to help out, I was thinking that you said you tested on your end and it was working fine, would you be able to send me how yours is coded so that I can look it over and hunt around for a discrepancy between yours and mine?

Yes, I did test the minimal example that we share in the docs and also tested the code from the second video link you shared. You can check it here: GitHub - amandeepmittal/GoogleAuthSessionExample: Expo AuthSession API + Google Sign in Provider

@amanhimself
This is very strange in that case, I have made sure everything is the same as in your example but i still get response?dismiss

Im going to open a new Github issue for this because there must be some difference between the expo testing environment you are using and what I have out here in the wild, but I have not been able to find it.

If you have any other idea please let me know, I am at a bit of a loss here, is it really not possible that there is a bug in the expo-auth-session/providers/google package that is causing it to fail on Android?

New Github Issue: expo-auth-session/providers/google Android Standalone Issue · Issue #22745 · expo/expo · GitHub

Did you try creating new credentials and generating new values for androidClientId in a new project?

I have tried deleting an re-generating my androidClientId but it seems to have had no effect, are you also suggesting I delete the project entirely in google console and setup the credentials again from scratch?

And just covering my bases here but the Sha1 fingerprint should be the one found in my expo Android credentials correct?

Yeah, I was suggesting creating a new project in Google console and then generate credentials for Android in that project and also using them in a new Expo project (with just the minimal example) just to see if it changes the results in your case.

I’d also suggest generating a new SHA1 fingerprint for this new project. I think testing out everything from scratch will be a good idea. For a new project, try to generate it from scratch. We describe that how to do so in a new project here: Authentication with Google and AuthSession API - Expo Documentation

@amanhimself Hmm ok then before trying that, which I’m open to doing, I have noticed something that lends credence to this being an issue on the Google Android Credentials being the cause of this issue

So last message I said that I removed and replaced the Android credentials and it was still behaving as it has been (response?dismiss). That looks like it was premature because now its not doing that, its is now passing me:

Access blocked: Authorization Error
The OAuth client was deleted
Error 401: deleted_client

Seems that Google is a bit behind in my credentials, because I do have a new Android credential in the google console and have updated my eas.json and .env file with it but I’m getting that error saying i don’t have / have deleted my Android Credentials.

Would happen to know if there is any reason why the app is not picking up the new Android Credential? Right now I’m thinking that the Android app has never been fed a correct set of credentials which might be the cause of the issue?

It seems like a possibility. I’m not sure why the app is not picking up the new Android credentials. All I can point you towards is to check the properties of generated credentials that package name and SHA fingerprint value match with that of your app.

From what I have found around stack overflow etc there its seems the older token is being stored in my app somewhere and being used that prevents it from picking up the new credentials

Where I am stuck on my end is this is referencing the issue for python and they have a token.pickle file in their working directory that they need to delete. Would you happen to know what that file’s JavaScript/ react-native equivalent would be? If I can find an delete that file, this seems like it might resolve the issue or at least let my ap p accept new credentials, but so far I haven’t been able to ID what this file is or where it stored in a java script app.

@amanhimself Hi again, so I did as you recommended and built a fresh app and accompanying fresh project in google console with new credentials
Sadly the results I’m getting are no different than on the original app, IOS worked without any issue but Android is still spinning then redirecting to the google homepage
One thing to note is that there is significant lag/ wait time on the Android version, the accounts selecting page takes a while and when selecting and account, tapping on it does nothing for a good 10-15 seconds and when it does finally work its spins and redirects to the google homepage

Non of this lag or slow down occurs on the IOS version which again leads me to that “race condition” noted in the first video, can it be that previous processes have not completed that block next steps and that causes the redirect/ dismiss issue? If so would that not be an issue in the providers/google package?

To illustrate I have also added a screen recording of IOS vs Android on the new fresh app to the Github issue

expo-auth-session/providers/google Android Standalone Issue · Issue #22745 · expo/expo · GitHub

Thanks for creating the issue, I’ll take a look at it.

@amanhimself Hi thanks for looking into this I know this has been a bit a pain to handle, one other thing I have also been able to rule out the Google Android credential as being the problem. I added react-native-app-auth and after a bit of hacking about it does connect to Google and bring back the user info and re-route properly. For some reason this is now causing my app not to see the Google map API Key but that’s obviously a separate issue and for you the key item is that this rules out the Android credential

Good to know that it rules out the Android credential part.

For what it’s worth, I’d still suggest using GitHub - react-native-google-signin/google-signin: Google Sign-in for your React Native applications library since it has a native API and config plugin. Also, it is becoming our recommendation to integrate Google as an auth provider. We’re working on updating our docs on our end (WIP: [docs] Update Using Google authentication guide by amandeepmittal · Pull Request #22813 · expo/expo · GitHub). It also means we’ll be deprecating Google and Facebook auth providers starting SDK 49 and will probably be removed in a future SDK.