Get tokens for native app and its backing API with a single auth flow using react-native-auth0

I have 2 Auth0 applications (1 API and 1 native app). The native app is built using react-native and react-native-auth0. The API supports our services and is the backing API for this native app.

I want to authenticate a user to the native app (something I have accomplished already), but I also want to get an accessToken for the backing API without making a 2nd call to react-native-auth0’s webAuth.authorize().

I have been able to call webAuth.authorize() using an audience/scope combo that gets me accessToken, idToken, and refreshToken for the native app, but that accessToken is not useful for my backing API. I also have an audience/scope combo that gets me an accessToken that is meant for the backing API as well as an idToken, but I can’t get a refreshToken.

Can anyone help untangle this for me? I just want users to log in once and have their app pull their user data and get access to our API.

Please include the following information in your post:

  • Which SDK this is regarding: react-native-auth0
  • SDK Version: 2.9.0
  • Platform Version: React Native 0.64.2

For anyone that reads this, the reason using the API audience with the offline_access scope didn’t work was that Offline Access was turned off on that API. I flipped the Offline Access switch in settings and that did the trick.

I know have all the tokens and user info I need.

1 Like

Perfect! Thanks for sharing it with the rest of community!