I have a question about light-oauth2 refresh tokens. It appears that they never expire so must be manually revoked, which IMO causes maintenance and security issues, and also seems to contradict the light-oauth2 docs.
(Note: My ears are open to explanations about this behaviour, as there may be very good reasons behind it. It is simply (at the moment) counterintuitive to me.)
More Details
The refresh tokens accumulate indefinitely in the refresh_token table. There does not appear to be any code in CacheStartupHookProvider that gives them a TTL. As you can see, the code that would seem to evict refresh tokens after 1 day has been commented out (lines 108-119):
// fresh token map with near cache and evict. A new refresh token will
// be generated each time refresh token is used. This token only lives
// for 1 day and it will be removed from the cache automatically.
MapConfig tokenConfig = new MapConfig();
tokenConfig.setName("tokens");
NearCacheConfig tokenCacheConfig = new NearCacheConfig();
/*
tokenCacheConfig.setTimeToLiveSeconds(24 * 60 * 60 * 1000); // 1 hour TTL
tokenCacheConfig.setMaxIdleSeconds(24 * 60 * 60 * 1000); // 30 minutes max idle seconds
tokenCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
tokenCacheConfig.setCacheLocalEntries(true); // this enables the local
*/
Also, the light-oauth2 docs state that:
"The authorization server issues a new refresh token and the client MUST discard the old refresh token and replace it with the new refresh token. The authorization server revoke the old refresh token after issuing a new refresh token to the client." (emphasis mine)
But my own tests show that this isn't happening. For example:
- Call the light-oauth2 code service (GET), and use the authorization code that was sent to the redirect uri.
- Call the light-oauth2 (POST: authorization code grant type) with the authorization code. It will return an authorization token T1 and a refresh token R1.
- Call the light-oauth2 token service (POST: refresh token grant type) with refresh token R1. It will return an authorization token T2 and refresh token R2.
- Call the light-oauth2 token service again (again, the POST: refresh token grant type) with refresh token R1. It will return an authorization token T3 and refresh token R3.
Step 4 seems to contradict the docs, which say that The authorization server revoke the old refresh token after issuing a new refresh token to the client. From step 4 above, however, it does not appear that refresh token R1 has been revoked even after the new refresh token R2 has been issued. R1 is still able to get new authorization tokens.
So now, R1, R2, and R3 can all be used to get new authorization tokens, and the set of useable refresh tokens keeps growing indefinitely.
My question is whether this is an omission or by design (and perhaps the docs should be updated). And if it is by design, what is the rationale for this? It would seem to me that
- its insecure to have so many never-expiring refresh tokens issued
- it creates a maintenance complication to have to manually remove refresh tokens from the database, rather than have them automatically expire and be evicted.
- adding so many new refresh tokens to the database is slower and seemingly unnecessary (e.g.: why is new refresh token needed every time a new authorization token is issued? It would seem more efficient if a new refresh token was issued ONLY in the authorization code grant type)
Thanks for any help