Auth session sometimes ends with "Something went wrong trying to finish signing in."

See original GitHub issue

Maintainer edit

For production apps, it is preferable for your app to navigate to the third-party authentication provider directly instead of using this service. This is the official workaround to this issue, which is likely unresolvable due to how browser cookie policies have changed.

Configure the authentication provider to redirect directly to your app, typically with a deep link with your app’s own URL scheme. In your app, set the useProxy option to false (the default) when calling the promptAsync method, which configures your app not to use this service.

Due to web browser changes like WebKit’s Tracking Prevention, the AuthSession proxy service may not work reliably in edge cases such as when a user’s device is configured to block cookies or prevent cross-site tracking. The AuthSession proxy service does not track nor collect any user data but it requires cookies to correctly redirect back to your app after the user has authenticated with the third-party authentication provider. This service will not work if the browser’s settings or heuristics block cookies.


🐛 Bug Report

Summary of Issue (just a few sentences)

Sometimes when I try logging in using AuthSession it doesn’t redirect me back to app, but shows “Something went wrong trying to finish signing in.” instead. After that when I try again, it works as it should. After numerous tests we assume that this only happens on iOS, it never got reproduced on Android.

I am using expo since version 33, and this never happened before.

Environment - output of expo diagnostics & the platform(s) you’re targeting

  Expo CLI 3.21.9 environment info:
    System:
      OS: macOS Mojave 10.14.4
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 10.16.1 - /usr/local/bin/node
      Yarn: 1.15.2 - /usr/local/bin/yarn
      npm: 6.9.0 - /usr/local/bin/npm
    IDEs:
      Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
    npmPackages:
      expo: ^37.0.0 => 37.0.11
      react: 16.9.0 => 16.9.0
      react-dom: 16.9.0 => 16.9.0
      react-native: https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz => 0.61.4
    npmGlobalPackages:
      expo-cli: 3.21.9
  Target env: Android & iOS

Reproducible Demo

All I’m doing is:

const {
  data: { redirect_url: redirectUrl }
} = yield ApiClient.get(`app.auth.${socialLoginSite}`); // fetch redirect url from backend, for google or facebook

const result = yield AuthSession.startAsync({
  authUrl: redirectUrl
}); // Everything happens in this call

Steps to Reproduce

Try logging in using facebook or google, for some reason sometimes the final redirect doesn’t work.

Expected Behavior vs Actual Behavior

Expected Behavior: If there is an error, then AuthSession should return with

{
  result: {
    type: "error"
    ...
  }
}

Actual Behavior: AuthSession gets blocked on last step and both users and developers are confused.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:9
  • Comments:70 (30 by maintainers)

github_iconTop GitHub Comments

7reactions
EvanBaconcommented, Jul 23, 2020

For future reference, I hit this error today when I misused the proxy.

const redirectUri = AuthSession.makeRedirectUri({
    useProxy: false,
});

// ...

promptAsync({ useProxy: false })

This caused the auth to open up to the provider (e.g. facebook.com) but redirect to the proxy auth.expo.io when it was complete. The error was the result of the auth proxy not being able to complete the result because I forgot to start it.

4reactions
ivanseniccommented, Feb 5, 2021

I can confirm that we managed to overcome this by not using the proxy in the production or better said when not using the expo client. We confirmed that the no-proxy solution works with the clients where we were able to reproduce the problem. We kept the proxy for expo client as it’s easier to handle dev and integration stages like this, but you can also fully move to no-proxy solution.

In addition, we had to move away from AuthSession.startAsync to AuthSession.loadAsync and AuthRequest.promptAsync. The reason is that we needed to supply correct information about proxy usage to both makeRedirectUri and promptAsync

Basically this worked for us:

export const isAuthSessionUseProxy = () => Constants.appOwnership === AppOwnership.Expo;

export const getAuthSessionRedirectUrl = () => AuthSession.makeRedirectUri({ native: 'com.myapp://my-redirect-path', useProxy: isAuthSessionUseProxy() });

export const fetchToken = () => {
  // maybe complete auth session first
  WebBrowser.maybeCompleteAuthSession();
  
  // resolve redirect url
  const redirectUrl = getAuthSessionRedirectUrl();
  
  const discovery = {
      authorizationEndpoint: `${Env.AUTH_HOST}/oauth/authorize`,
      tokenEndpoint: `${Env.AUTH_HOST}/oauth/token`
  };
  
  return AuthSession.loadAsync(
      {
          clientId:..,
          redirectUri: redirectUrl,
          extraParams: {
              // anything else you want to pass to authorize endpoint as request param 
          }
      },
      discovery
  )
  .then(request => request.promptAsync(discovery, { useProxy: isAuthSessionUseProxy() }))
  .then(result => { 
     // get the token with the code if the result is successful 
     // don't forget to use the same redirectUrl
   });
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix Google expo auth session sign in Error "Something ...
Show activity on this post. I'm trying to implement google sign in in my expo using expo-auth-session, When I click on my gmail...
Read more >
AuthSession - Expo Documentation
AuthSession is the easiest way to add web browser based authentication (for ... It handles failures and provides information to you about what...
Read more >
React-Native Expo App Auth0 Login, Authsession - Authurl Fails
Sometimes when I try logging in using AuthSession it doesn't redirect me back to app but shows Something went wrong trying to finish...
Read more >
Line login | Voters - Expo - Canny
Im use Line login with expo-auth-session. with expo-dev-client. has issue 'Something went wrong trying to finish signing in. Please close this screen to...
Read more >
Common questions about the Microsoft Authenticator app
To remove the app from a device using a work or school Microsoft account, go to the two-step verification area of either your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found