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 and WebBrowser libraries, which adds web browser based authentication to your app.

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

Install Expo’s AuthSession Package

We’ll be using the AuthSession.makeRedirectUri() method to generate a RedirectUri for us to use.

You’ll also want to add the WebBrowser package to your React Native Expo project using the following:

Install Expo’s WebBrowser Package

For our purposes, we’ll specifically be using the WebBrowser.openAuthSessionAsync() method, which you can read more about here. We will be using two arguments:

  • url: This will be the Authorization URL we generate using the WorkOS API
  • redirect: 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 url argument in the openAuthSessionAsync() method. In the code, 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!