bjerkio/oidc-react

Enabling automaticSilentRenew constantly refreshes tokens

ctron opened this issue · 5 comments

ctron commented

Setting the option automaticSilentRenew to true constantly refreshes (every few seconds) the token. Which, if propagating this to websockets, leads to constant updates and unnecessary traffic on the SSO instance.

I would expect that the token only gets refreshes X seconds before the token expires.

Are you sure it's not the iframe that's checking the user session status at the token server every two seconds to see if it's changed? There's an iframe that calls the check_session endpoint and one that does the renewal based on the current user's token's expiration. Or maybe your server is setting the expiration to expire immediately. Or maybe the app is calling login repeatedly which might give you a new token each time. Is it the access token value that's changing or just the expiration or the session status?

Another thought is to set that prop to false and use the event addTokenExpiringEvent where you can implement your own logic prior to expire and then decide when/whether to call silentSignIn or whatever it is that renews the token with the token server.

ctron commented

Ok, I think I have found out the cause for this. The livespan of the access token is pretty short (1m) and it turn out, digging through the code, that there is an accessTokenExpiringNotificationTimeInSeconds of 60 seconds. Which indeed refreshes the token all the time.

I think it would be great if this was: a) mentioned in the docs of the automaticSilentRenew property and b) would be configurable through the properties.

@ctron do you get access token properly updated in useAuth() hook also? I'm struggling with this. I see the token is updated in local storage, but userData.access_token in useAuth() stays the same and I'm getting 401s after the token is expired. Do you use some special page to set this manually and use it as silentRenewUrl or this should happen automatically behind the scenes?

Interesting. Sounds like getUser isn't being called to update cache, try that before your call

ctron commented

@Episodex I think that works for me. I am not doing anything special.

I will close this issue, as my original issue wasn't an issue with this project.