How to Implement Web (NextJS) to Mobile SSO(React Native) via Deep Link in Auth0 React Native Applications

Overview

Implementing Web-to-Mobile Single Sign-On (SSO) via deep links in Auth0 React Native applications requires relying on standard OpenID Connect behavior. When a mobile browser sets an SSO session cookie on the Auth0 tenant domain, native components like ASWebAuthenticationSession or Chrome Custom Tabs share this cookie jar. Trigger the authorization method upon deep link interception and disable ephemeral sessions to achieve seamless SSO without complex token exchanges.

Applies To

  • Auth0
  • React Native 
  • Next.js 
  • Single Sign-On (SSO)
  • Deep Linking

Solution

To implement Web-to-Mobile SSO, configure the React Native application to intercept the deep link, disable ephemeral sessions, and trigger the authorization method by following these steps:

  1. Ensure the web application uses @auth0/nextjs-auth0 to set an SSO session cookie on the Auth0 tenant domain when accessed via a mobile browser, such as Safari on iOS or Chrome on Android.
  2. Configure the React Native application to intercept the deep link when the user taps the link.
  3. Verify that Ephemeral Sessions are disabled in the React Native application. This allows the native components (ASWebAuthenticationSession on iOS and Chrome Custom Tabs on Android) to share the cookie jar with the device's default system browser.
  4. Trigger the authorize() method from the react-native-auth0 SDK to authenticate the user using the existing session cookie.
  5. Implement the following code snippet inside the component or hook that handles the deep link to execute the authentication flow.
    import { useAuth0 } from 'react-native-auth0';
    
    // Inside the component or hook that handles the deep link
    const { authorize, user } = useAuth0();
    
    const handleDeepLink = async () => {
      if (!user) {
        try {
          await authorize(); 
        } catch (error) {
          console.error("SSO Login failed", error);
        }
      }
    };

Related References

Recommended content

No recommended content found...