The basic idea is that the user session should be long and be continued/disabled based on user activity. However, as we couldn’t revoke token so the token should be short-term such as 15 mins. If we can refresh the token after it’s expired then the user session could be continued.
After some research, I found there are two implementations for this purpose:
One for refresh expiration, one for token expiration. The refresh TTL is longer than token expiration TTL. The client will call server refresh api if it found current token is expired but still could be refreshed. The new token will have new expiration time and refresh expiration time. If both TTL expired, then that token is invalid and user is required to do authentication again. Pros * Requires No additional auth server. * The data of token could be modified so it can replace session under particular situations. Cons * The refresh token couldn’t be revoked.
The refresh token is long-live, one week for example. The access token(JWT could be used here) is short-live, 15 mins for example. The client holds both tokens, every time it found access token expired(could be read from the payload of access token), it goes to auth server with refresh token asking for a new access token.
Pros
Cons
Let’s assume that in option 1, the token expiration time is 15 mins, and the time gap between token expiration and refresh expiration is also 15 mins. In option 2, the access token expiration time is 15 mins, and the refresh token expiration is one week.
My question is, is option 2 more secure than option1?
Our product is currently using distributing session just for storing user info. We wants to eliminate the use of auth server and session but security is our first priority. I didn’t see much advantages of option 2.
Am I misunderstanding something or any better token control strategy I missed? Any advices would be greatly appreciated.
The only point of having a refresh token is to allow user sessions to be renewed, without having users enter their password again.
Let's split a few uses cases
Consider a session in a banking website, a payment site, or a public cloud (an AWS admin token could delete all a company infra).
For this use-case, it must not be possible for sessions to be extended without user authenticating again, so there is no point in refresh tokens. Deliver short lived access tokens and don't deliver refresh tokens at all (they can be disabled in the OIDC provider).
Consider a session in a mobile application, could be a game, could be an app (facebook).
For this use-case, it would be nice to have sessions that can live very long but then it's important to be able to cancel them (device lost or stolen). Deliver access tokens for a day and deliver refresh tokens for 3 months.
When the application is opened, it can request a new session with the refresh token then work with it. It's possible to revoke a device access by invalidating the refresh token (see the "my active devices" in facebook/gmail for example).
Only minor downside is the user has to authenticate again if the application isn't used for months, which is reasonable in my opinion. (marketing/growth departments view may differ and they will probably ask to make it longer -how about infinite?-. better not make it longer than a year).
I am focusing on mobile applications here but web sites can be similar to some extent. The difference is that (browser) cookies on a laptop/desktop are extremely easy to extract, notwithstanding end-users having a ton of malware/adware potentially siphoning them out. So the environment is not quite as trustworthy, which is a concern for storing long lived tokens.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With