Hello Everyone,
I created this Topic to ensure that no one else fall in the error that the API returns always 86400 as the time that supposedly the token is going to expire.
Auth0 return you a JWT when you use the: ‘Username-Password-Authentication’, with grant_type “password”.
After you successfully configure everything and send the HTTP request a response like this is send to you:
{
“access_token”: “ABCD”,
“refresh_token”: “JDKF”,
“id_token”: “HERE.ISYOUR.TOKEN”,
“scope”: “openid profile email offline_access”,
“expires_in”: 86400,
“token_type”: “Bearer”
}
You will ALWAYS receive a supposed “expires_in” with value “86400” inside your response, but this is not trustworthy at ALL.
What you have to do to fix this error?
If you open your JWT with a visual debugger like this: " h t t p s : / / j w t . i o /" (just copy and paste the “id_token” there ), you will notice that your token have a body part (as the standard regulates it), something like this:
Like every JWT, there are 2 important fields so that you can now when is going to expire your token and when was issued. Those fields are: “iat” and “exp”
{
“nickname”: “nick.name”,
“name”: “name”,
“picture”: “picture”,
“updated_at”: “2020-01-25T11:45:49.902Z”,
“email”: “vadrian.eguez@gmail.com”,
“email_verified”: true,
“iss”: “link”,
“sub”: “auth0|5e175b205081450e8da5ef33”,
“aud”: “971tc3Ij27pb4O0R6rkykhTOFsMoreLU”,
“iat”: 1579952749,
“exp”: 1579988749
}
Those fields are like the getTime()
method that returns the number of milliseconds since January 1, 1970, when you compare the time between both dates, this time matches the field JWT Expiration in seconds that is configurable in your account:
SO,
To fix this error, you have to parse your JWT and use those dates to ensure when you really have to refresh the JWT.
That was the fix.
I hope this information is useful for everyone.
Greetings my friends,
Info Manticore-Labs Team.