WorkOS Docs Homepage
Integrations

React Native Expo

Learn how to integrate WorkOS SSO into a React Native Expo app.

When it comes to combining the WorkOS SSO solution with mobile applications, our advice on the general flow tends to go like this:

  1. Make an API call to generate an Authorization URL.
  2. Send the end user to the generated URL within their mobile browser.
  3. Deep-link the end user back into your native application upon successful authentication.

With Expo, you’re able to integrate the WorkOS API with the Expo AuthSession library, which adds web browser based authentication to your app. You can see their full documentation for the library here.

To get started, you’ll want to add the the AuthSession package to your React Native Expo project using the following:

Install Expo’s AuthSession Package

For our purposes, we’ll specifically be using the AuthSession.startAsync() method, which you can read more about here. This method takes two required arguments:

  • authUrl: This will be the Authorization URL we generate using the WorkOS API
  • returnURL: This will be the link back into your native Expo application once authentication is complete

The first step in the authentication process will be to Get the Authorization URL and use it as the authUrl argument in the startAsync method. In the code (using Typescript in particular) it would look something like this:

Get Authorization URL Call

Once the above is in place, you will ultimately have a code which you can then exchange in one more API call for the user profile of the authenticating user. You’ll be making a POST request to Get a Profile and Token with the token, as shown here using Axios:

Exchange OAuth Code for Profile and Token

From the end user’s side, they will be sent to the native UI of their Identity Provider in their mobile browser. After they authenticate with their credentials, they will be dropped back into the native application, ready to go.

That’s all there is to it! By combining WorkOS SSO with React Native Expo AuthSession, adding Single Sign-On to your Expo app is a total breeze with minimal code needed.

To test the React Native Expo flow for yourself, head over to the GitHub repository of our example React Native Expo application and give it a whirl for yourself!