Issues with AuthSession implementation: Dismiss or no redirect

  1. SDK Version: 37.0.12
  2. Platforms(Android/iOS/web/all): Android/(all?)

I am having issues with the implementation of Expo Auth Session.

I am trying Google Oauth Login in Expo Auth Session as documented here: https://docs.expo.io/guides/authentication/#google

WebBrowser.maybeCompleteAuthSession();

const GoogleButton = () => {
  // Endpoint
  const discovery = useAutoDiscovery('https://accounts.google.com');

  // Request
  const [request, response, promptAsync] = useAuthRequest(
    {
      clientId: 'MYID',
      scopes: ['email', 'profile'],
      // For usage in managed apps using the proxy
      redirectUri: makeRedirectUri({
        // For usage in bare and standalone
        native: 'com.googleusercontent.apps.MYID://redirect',
        useProxy: true,
      }),
    },
    discovery,
  );

  console.log(request);
  console.log(response);

  return (
    <Button
      onPress={promptAsync}
      icon={GoogleIcon}
    />
  );
};

The browser opens, I can successfully log in with google, but when I get redirected to the app, response resolves to Object { "type": "dismiss", }

I also tried implementing oauth with a different oauth service:

WebBrowser.maybeCompleteAuthSession();

const HiveButton = () => {
  // Endpoint
  const discovery = {
    authorizationEndpoint:
      'https://hivesigner.com/login-request/my.app',
  };

  // Request
  const [request, response, promptAsync] = useAuthRequest(
    {
      scopes: ['posting'],
      // For usage in managed apps using the proxy
      redirectUri: makeRedirectUri({
        useProxy: true,
      }),
    },
    discovery,
  );

  console.log(request);
  console.log(response);

  return (
    <Button
      onPress={promptAsync}
      icon={HiveIcon}
    />
  );
};

The browser opens, I can log in successfully, but instead of being redirected to the app, I get “Something went wrong trying to finish signing in. Please close this screen to go back to the app.” on auth.expo.io/@me/myapp, even though the parameter code has the correct login token that I want to pass to my app.

1 Like

i have the exact same issue. I don’t think the proxy works.

For that second issue: you need to pass { useProxy: true } to promptAsync, so it becomes: ({ useProxy: true }), or in your case onPress={() => promptAsync({ useProxy: true }).

See AuthSession - Expo Documentation

1 Like

Thanks! I’ve now solved the second issue by using AuthSession.startAsync instead:

 const handleLogin = async () => {
    const redirectUrl = AuthSession.getRedirectUrl({ useProxy: true });
    const response = await AuthSession.startAsync({
      authUrl: `https://hivesigner.com/login-request/my.app?redirect_uri=${redirectUrl}&scope=posting`,
    });
console.log(response)
}

Instead of using AuthSession for Google login I’m using the expo-google-sign-in implementation

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.