Google Redirect Url For Development Setup Using Expo-auth-session

1.6k Views Asked by At

I am are trying to get Oauth flow working on a mobile app built with React Native and the "expo-auth-session" library, which has out-of-the-box support for Google OAuth. See https://docs.expo.dev/guides/google-authentication.

The redirect URI works if we enter a production value such as "com.mydomain.myapp:/oauth", but the expo-auth-session library provides tools to run development apps locally using a local HTTP server. In this scenario, the redirect URI value needs to be something similar to "exp://192.168.128.57:19000/--/oauth2", which google does not allow, as we get an error "Access blocked: authorisation error" - "Error 400: invalid_request". Note that we have also tried using localhost with a redirect uri such as "exp://localhost:19000/--/oauth2", which also results in the 400 error.

 const redirectUri = makeRedirectUri({
    scheme: 'com.mydomian.myapp',
    path: '/oauth2',
    preferLocalhost: true  // also tried false
  });


  const [request, response, promptAsync] = Google.useAuthRequest({
    androidClientId: ANDROID_CLIENT_ID,
    iosClientId: IOS_CLIENT_ID,
    redirectUri: redirectUri,
    scopes: ["profile", "email"]
  }, {
    useProxy: false
  });
1

There are 1 best solutions below

0
On

From my exp, on expo version you are working on(it should be 49 or 50), expo allows you to use normal redirect URi only within the development build to work in simulator.

Development build mean that you should run script expo run:ios, with installed package expo-dev-client. Also I use expo account with setup oauth proxy to handle that locally. https://auth.expo.io/