How to get a refresh token after Expiring current access token in salesforce React-native?

145 Views Asked by At

import { net, oauth } from "react-native-force";

oauth. getAuthCredentials( (data) => {

})

This is how I call to get the credentials Need to automatically fetch the refresh token when the access token expries?

do we need to enable or do i need to call any methods in order to automatically get the refresh token using the expired access token? without the user logout and logging in

1

There are 1 best solutions below

0
On

I know almost nothing about React so can't help you with exact code but I know you're using words in confusing way. Makes it harder to understand the documentation and ask the right question.

You are supposed to receive access_token and refresh_token as part of the original login call. If you asked for the refresh_token in the OAuth scopes. https://stackoverflow.com/a/71842692/313628 You'd then use up access tokens immediately as you currently do but store the refresh_token somewhere in your database(?) for future use.

If you did not ask for refresh token in scopes - you will have to ask for new login. There's no magic promoting existing access (limited by originally requested scopes) "up" to include more scopes. Whatever new thing you need (refresh token, maybe bumping up from just chatter use to view all data on user's behalf...) - new authorisation flow.

And then... if access_token expired - pull the refresh token from your database(?) and execute this: https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_refresh_token_flow.htm&type=5. However this is simplified in your React library or worst case it looks like a simple HTTP POST, you could even do it as a raw request?