Logout with Expo

Hi there,

I’m facing similar problems to the following unresolved issues:

I’m able to log in to auth0 using the example here: https://github.com/expo/examples/tree/master/with-auth0

I’m using the following to try to log the user out
await WebBrowser.openBrowserAsync(
${myAuth0Domain}/v2/logout?client_id=${auth0ClientId}&returnTo=${redirectUrl},
)

When I do so and check the logs in the auth0 console, I see a successful logout. However, when I hit the /authorize endpoint again, I’m still logged in.

I’ve seen Logout, but it’s not clear from those docs how I can clear the appropriate cookies since I can’t use the react-native SDK with expo.

Any help would be appreciated.

Thanks,
Noah

Noah, have you been able to solve this? I’m seeing the same behavior and am also a bit puzzled. But maybe it’s something we need to take up with the Expo folks?

Thanks

Hannes

Hi @hannes.hesse ,

This has shifted down my list of priorities lately, and I haven’t figured out a solution yet. I was doing some digging during the holiday break, and I think the solution lies somewhere in the expo AuthSession docs. Specifically, my next shot would be to mess around with some of the methods exposed there, specifically AuthSession.revokeAsync(). I still haven’t attempted this solution, but I think the issue has to do with cookies being passed back from the expo WebBrowser that AuthSession is built on top of.

So, using WebBrowser.openAuthSessionAsync instead of openBrowserAsync works for me – though I’m not clear why.

2 Likes

I am facing the same issue - WebBrowser.openAuthSession with the URL as the logout endpoint kills the session, but shows all the messaging as if you are getting logged in. If anyone has seen a better solution for sign out with this browser flow and expo-auth-session, I would love to hear it.

2 Likes

Thank you so much! It solved my problem, logout from Keycloak:
Login: useAuthRequest…
Logout:
let logoutUrl = http://192.168.0.10:8182/realms/SpringBootKeycloak/protocol/openid-connect/logout;
await WebBrowser.openAuthSessionAsync(logoutUrl);

I’ve been using this approach until recently when I added a sign out button inside of a Drawer navigator’s menu and the app was crashing after the sign out flow finished.
My apps are using Keycloak for authentication and the fix was to also provide id_token_hint (which is literally the ID token of the user) through query params so it does not get the user to a page where they need to press a button to logout. Now I just make the request with axios and it works properly.

Sample code:

export const logout = async (idToken?: string) => {
  const discovery = await getDiscoveryAsync();

  const params: Record<string, string> = {
    client_id: CLIENT_ID,
  };

  if (idToken) params.id_token_hint = idToken;

  const paramsStr = Object.entries(params)
    .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
    .join("&");

  const response = await axios.get(
    `${discovery.endSessionEndpoint}?${paramsStr}`
  );

  if (response.status !== 200) return false;

  return true;
};

Hi there, and welcome everyone to the Auth0 Community!

Thank you, @ferretwithaberet, for sharing your solution with the rest of the community!

Teamwork! :handshake:
Dawid