How to get a new access token after Expiring current access token in salesforce React-Native?
Closed this issue · 4 comments
I am developing a hybrid app using Salesforce react-native. When the access token expires I must handle the re-login process. I want to get a new access token after it expires the current access token without the user logout and re-login.
I have used the below code to get current user data and it returns current user data
import { oauth } from "react-native-force";
oauth.getAuthCredentials(
(res) => resolve(res),
async (e) => {
reject(e);
}
);
but when I called the below code to get a new access token after it expires in the Android app, it returned a new access token but the IOS app logout from the oauth.
oauth.authenticate(
(res) => resolve(res),
async (e) => {
reject(e);
}
);
I need to get a new access token after expire current access token. When the access token expires I must handle the re-login process. I want to get a new access token after it expires the current access token without the user logout and re-login.
I would do a cheap authenticated call to "rehydrate" the access token if needed and then do the call to getAuthCredentials
. That would ensure that the access token is valid.
import {oauth, net} from 'react-native-force';
net.resources(
(response) => {
oauth. getAuthCredentials(...);
}
);
@wmathurin, After Expiring the Token there is an Error SalesforceNetReactBridge.sendRequest failed: "{\"error\":\"Could not refresh token\"}"
. The App logout from the auth.
I am also facing the same issues.
But also make sure to check your refresh token policy (see paragraph 7 on https://help.salesforce.com/s/articleView?id=sf.connected_app_manage_oauth.htm&type=5).