'How to refresh auth tokens with react-native-auth0?
I'm implementing authentication with react-native-auth0 and was looking for a way how to obtain refreshToken and how to use it to get new accessToken and idToken tokens.
Solution 1:[1]
Basically I used auth0.passwordRealm for implementing login with email/password:
import Auth0 from 'react-native-auth0';
...
const config = {
username: email,
password: password,
realm: 'Username-Password-Authentication',
scope: 'openid profile email offline_access',
audience: 'https://' + Auth0Config.domain + '/userinfo',
};
const credentials = await auth0.auth.passwordRealm(config);
Auth0 doesn't send you refreshToken until you put offline_access into scope prop. In my case accessToken lives 24 hours which is mentioned in expiresIn prop of credentials. And now we can use refreshToken for requesting new tokens.
const newCredentials = await auth0.auth.refreshToken({
refreshToken: credentials.refreshToken,
scope: 'openid profile email offline_access',
});
newCredentials now contains updated accessToken and idToken. You will also get new refreshToken if you have Refresh Token Rotation enabled in Auth0 dashboard.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aliaksei |
