Refresh tokens - okta-react-native

I am using a custom sign-in with a react-native app, similar to the example provided by Okta here: https://github.com/okta/samples-js-react-native/tree/master/custom-sign-in

As you can see in LoginScreen.js, it is using the signIn method from okta-auth-js library to get a sessionToken, and then calling the authenticate method from okta-react-native SDK to get the accessToken.

This all works fine for me, but I’m unsure of how to refresh the accessToken manually. There’s a method in okta-react-native called refreshTokens but it is throwing an error when called: Error: Error fetching fresh tokens: Unable to refresh expired token without a refresh token.

I do not see a way to get a refreshToken in the documentation for neither okta-auth-js nor okta-react-native. I need to refresh the accessToken every time the user makes a request to the server. This is how my app works currently, and I’m trying to migrate to Okta with minimal impact to the app flow.

I’m able to use this flow in a React web app by calling authClient.tokenManager.renew('accessToken') but this does not work in a react-native application.

Can someone please advise how I can refresh the tokens?

PS. I do not want to use the webview modal login that Okta provides with the signIn method, as it is very disruptive to my app flow.

silly question, but does your application configured to support refresh tokens? are you requesting the offline scope to get the refresh token?

2 Likes

Thank you. Looks like that was the issue. I did not have access to the config but got an admin to check off that box. I can now call refreshTokens() successfully.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.