5

I'm trying to implement Google OAuth 2 signin using FormidableLab's react-native-app-auth library in my react native android application as shown below:

  googleLoginPressed = async () => {
    const config = {
      serviceConfiguration: {
        authorizationEndpoint: 'https://accounts.google.com/o/oauth2/v2/auth', tokenEndpoint: 'https://accounts.google.com/o/oauth2/v2/auth', 
      },
      clientId: app_params.GOOGLE_CLIENT_ID, redirectUrl: 'https://<my_domain>/oauth/google',
      scopes: ['openid', 'profile', 'email'], additionalParameters: { 'response-type': 'code' },
    };
    try {
      const result = await authorize(config);
    } catch (error) {
      console.log(error);
    }
  }

This invokes a web view with Google's signin page and I could successfully authenticate myself. Google then correctly redirects to my oauth callback endpoint and populates the oauth code in the redirect url like it should. At this point, I expect react-native-app-auth to get the control back from the webview to application. Instead, the web view stays open at the redirect url page.

I have added necessary website association configuration under AndroidManifest.xml and the following code under MainActivity.java to check for getting the control back to application from the redirect url:

  @Override
  public void onNewIntent(Intent intent) { // this is not getting hit
    super.onNewIntent(intent);
    Uri appLinkData = intent.getData();

    if (appLinkData != null) {
      bar = appLinkData.getPath();
    }
  }

What I tried so far

  • I ensured my app can open Universal links. So website association must be working fine.
  • Also tried replicating the entire setup on iOS. Same result. The webview shows Google correctly redirecting to oauth endpoint but app fails to get control back.

How do I get control back from oauth web view to my react-native code?

Rakesh Singh
  • 858
  • 1
  • 12
  • 31

1 Answers1

0

If you are using Claimed HTTPS Schemes, which is the most recommended security option for mobile apps, you are likely to also need an interstitial page after login, that triggers the Universal Link.

My blog post has further info and a code sample you can run, though it uses plain Kotlin rather than React Native.

Gary Archer
  • 22,534
  • 2
  • 12
  • 24