oidc-client-ts
oidc-client-ts copied to clipboard
Token Expiration Timing Issue Due to Browser Throttling
Hi, I hope all is well!
Background
- I am using tokens with a lifetime of 5 minutes.
- Requests are being sent to my API with my token within an interval.
- Chrome and Edge browsers
Issues:
My token is sometimes being sent to my API when there is only 1 second left on the token when using the default settings. I expected it to be refreshed when there is 1 minute left on the token (+/- 5 seconds due to the interval set here: Timer.ts#L38).
After some analysis, I concluded that this happens when the browser is minimized, which causes the browser to throttle the timer so that it only runs the callback every 1 minute instead of every 5 seconds. When I enabled logging, I could see that the callback was sometimes triggered when the token had 1 second left for expiration.
I have seen some discussion on this in other issues here, but no issue ticket was describing the issue I am seeing now. Also, the behavior of the root cause is discussed here https://issues.chromium.org/issues/40284098 and https://developer.chrome.com/blog/timer-throttling-in-chrome-88.
I am going to test increasing the token expiration notification time from 60 to 80 seconds to get a 20-second cushion on the edge cases where the browser does a 60-second throttle on the interval timer.
But I was wondering if there is a better solution to be implemented in the library? Maybe using some type of background service or similar so that we are not affected by the browser's optimization?
Thank you for your assistance!