question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refresh token renewal

See original GitHub issue

While the library handles Access Token refreshing with silent renew, it doesn’t take into account the Refresh Token expiration time at refresh_expires_in. https://github.com/authts/oidc-client-ts/blob/8d8a700b23a2fffdada0b3ecaf271bc16a74759d/src/UserManager.ts#L226-L232

Assuming the user either sets automaticSilentRenew or uses events to do the same, this forces a constant Access Token refresh cycle when Refresh Token expiration time is less than accessTokenExpiringNotificationTimeInSeconds, since Access Token expiration time is limited by the Refresh Token expiration time.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Badisicommented, Aug 31, 2022

I once reported the same issue with the previous library version (different scenario though) : oidc-client-js#948

Issue is still relevant with oidc-client-ts and @atomicbrainman’s proposal to fix it seems the way to go.

1reaction
atomicbrainmancommented, Aug 31, 2022

@longsleep

refresh_expires_in is unsupported and afaict also non-standard. What providers/services do support it at the moment?

It seems at least Keycloak does support it, I don’t know about the others.
And actually, we don’t need it to detect a session that is bound to expire soon.

Also, there are no errors when refreshing the token.
Let’s use an example to clarify the issue:

Say, we have an auth server with the following setup:

  • Session time set to 12 hours (Refresh Token time)
  • Access Token expiration time is set to 20 minutes

And the user:

  • Has an existing session that expires in 22 minutes
  • Has an expired Access Token, but a valid Refresh Token
  • Client is configured with automaticSilentRenew: true and accessTokenExpiringNotificationTimeInSeconds: 60

The client does the following:

  1. [Time passed: 0] Automatic silent renew successfully requests a new Access Token. It’s expiration time is 20 minutes.
  2. [Time passed: 19 minutes] Again, automatic silent renew successfully requests a new Access Token. But it’s expiration time is 3 minutes, same as the time left before Refresh Token expires.
  3. [Time passed: 21 minutes] Access Token is about to expire again. So automatic silent renew successfully requests a new Access Token. It’s expiration time is 59 seconds.
  4. [Time passed: 21 minutes 1 second] Automatic silent renew goes into a cycle of successful requests to refresh the Access Token. But the returned Access Token has an expiration time of less than 1 minute, so the next request is fired almost immediately after the previous one finishes.
  5. [Time passed: 22 minutes] Automatic silent renew finally fails to renew the token and the client raises a logout event.

Step 4 is the issue here. On step 3 we can detect that the returned Access Token has an expiration time less than what is set in accessTokenExpiringNotificationTimeInSeconds and do something to prevent step 4, e.g. logout the user immediately.

A simple way to reproduce the issue would be to setup your client with a very large accessTokenExpiringNotificationTimeInSeconds, e.g. set it to 1000000

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Are Refresh Tokens and How to Use Them Securely
Once they expire, client applications can use a refresh token to "refresh" the access token. That is, a refresh token is a credential...
Read more >
Refresh Tokens - OAuth 2.0 Simplified
Access tokens can expire for many reasons, such as the user revoking an app, or if the authorization server expires all tokens when...
Read more >
Refresh a Token - Box Developer Documentation
A Refresh Token is valid for 60 days and can be used to obtain a new Access Token and Refresh Token only once....
Read more >
Does the refresh token expire and if so when? - Stack Overflow
Refresh tokens will expire X days (or hours) after their creation. Depending on your security requirements this expiration will be 1 month ...
Read more >
Microsoft identity platform refresh tokens
Refresh tokens have a longer lifetime than access tokens. The default lifetime for the refresh tokens is 24 hours for single page apps...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found