How to retrieve refresh token using auth0/auth0-react

  • Which SDK this is regarding: auth0-react
  • SDK Version: 1.7.0
  • Platform Version: Node v14.17.5

I have followed the Auth0 Ionic & Capacitor (React) SDK Quickstarts: Login guide to add Auth0 login to a Capacitor app, an iOS app to be specific.

The guide explains how to login and all that works well. But we would like to store the refresh token you get, store it in the secure app storage and then use that (if not expired) next time the use opens the app. The question is: how do I get the refresh token? I can’t see any methods for getting that token. The library uses auth0/auth0-spa-js under the hood, and I don’t see any way to get the refresh token from that library either. It looks like it’s configured to work automatically. But in this case we would like to store it to use it later on. Is that possible?

Thanks!

We found a solution ourselves. You can pass useRefreshTokens: true to the Auth0 provider and use a specific cache. I found the documentation here: https://auth0.github.io/auth0-react/interfaces/auth0_provider.auth0provideroptions.html. Then the package solves the rest for you automatically.

1 Like

Note that the API your requesting to must have “Allow Offline Access” enabled in order to get the refresh token returned from getAccessTokenSilently.

Once you’ve done that and confirmed the refresh token is returned on the token response, using getAccessTokenSilently with ignoreCache: true and scope: "offline_access" options set and you’re good to go!