React SDK get token expire_in

Please include the following information in your post:

  • Which SDK this is regarding: React SDK
  • SDK Version: 1.10.2
  • Platform Version: JavaScript
  • Code Snippets/Error Messages/Supporting Details/Screenshots: Added
{
  "access_token": "eyJhbGciOxxxxxxxxxxxx",
  "id_token": "eyJhbGcixxxxxxxxxx",
  "scope": "openid profile email",
  "expires_in": 86400,
  "token_type": "Bearer"
}

above is the response I see in Browser Developer tools Network tab when invoked getAccessTokenSilently.

I’m trying to get the expires_in and use it to re-invoke getAccessTokenSilently if the token is expired.

    getAccessTokenSilently().then(( token ) => {
      console.log( token );
    })

But getAccessTokenSilently is returning only the access_token but I want to get the expires_in as well.

Any workarounds are also welcome.

4 Likes

Is there a way to get all the other properties besides the access_token?

I would love to have an update for this quickly as it seems this question has been around since 2022 and there hasn’t been any answer.

1 Like

Hi @rkrishna, @quang.dang !

In the access token returned by getAccessTokenSilently, you can find the same information (the time when the access token expires) as the expires_in from the Network tab gives yo.
You would just need to decode the token to see its claims.

The value of expires_in (measured in seconds) = the exp cliam - iat claim of the access token.
The meassure of these two claims is seconds sinc Unix epoch.

To decode the access token, you can use one of the libraries listed in JSON Web Token Libraries - jwt.io - more tutorials are on the respective GitHub pages.

I hope this helps!

In case, more guidance is needed, Auth0 Professional Services 39 can definitely assist in designing/implementing an architecture to suit your UX needs, aligning with security best practices.

PS: Please make sure the token is jwt (you will get this format if you provide the audience parameter to the authorize endpoint).