Problem statement
One approach to check if an existing session is still valid is to access the expiresIn property in the access token. However, when setting the Token expiration (Seconds) found under API → → Token Settings to a specific value, this value does not get reflected at the time of retrieving the value using React-native SDK.
The SDK used is react-native-auth0 SDK version 2.16
The snippet of code to retrieve the token expiration time is as follows:
const getCreds = async () => {
const creds = await getCredentials();
return creds;
};
const creds = await getCreds();
const tokenExpirationDate = new Date(creds.expiresIn * 1000);
Why is the Token expiration value not reflected?
Symptoms
Tested in the following scenarios / workflows:
Scenario 1:
- Open application and login
- Go to the dashboard and change the "Token Expiration (Seconds)” to 30 days (in seconds)
- Open application logout
- Open application login
- Check the expiresIn property
Scenario 2:
- Go to the dashboard and change the "Token Expiration (Seconds)” to 30 days (in seconds)
- Install freshly the application
- Open application and login
- Check the expiresIn property
Expected result: “expiresIn” shows 30 days
Actual result: “expiresIn” shows only 1 day
Troubleshooting
Checked the parameters used in the call to authorize() method, and there was no audience parameter used. This audience parameter must be included.
Solution
To have this value reflected correctly, create a custom API and set the correct value for the “audience” parameter in the call to authorize. When this audience parameter is included, the value of the “expiresIn” is updated accordingly.