Avoid an OIDC refresh token call if the JWT refresh token has expired #43081
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #41830.
This PR is really about an optimization as opposed to a bug fix. If Quarkus OIDC can figure out that the refresh token has expired, then there is no point to attempt to use it and make another call to refresh the tokens, as it will fail anyway.
So the PR checks if the refresh token is in JWT format as in the case of #41830, and if yes, it checks the expiry
exp
claim, which is a number of seconds from the epoch, and if it is less than the current time, it has expired, and no another refresh call is made.I've done a minor code refactoring, where the refresh token is checked, just to avoid some duplication, but the only new change which is made here is this refresh token expiry check.
Added a test to confirm it is effective.
This PR will most likely benefit Keycloak users only as it is the only provider I know of which allocates refresh tokens in the JWT format. Most other providers issue binary refresh tokens. In the future, we might be able to support checking the expiry of binary refresh tokens too if their expiry time is returned as a JSON property...