Skip to content

Commit

Permalink
Request re-authentication if the OIDC session key is unresolved
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed Jan 16, 2025
1 parent ff1cccb commit 674888b
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,29 @@ public Uni<? extends SecurityIdentity> apply(Throwable t) {
.hasErrorCode(ErrorCodes.EXPIRED);

if (!expired) {
String error = logAuthenticationError(context, t);

Throwable failure = null;

boolean unresolvedKey = t
.getCause() instanceof org.jose4j.lang.UnresolvableKeyException;
if (unresolvedKey && OidcUtils.isJwtTokenExpired(currentIdToken)) {
// It can happen in multi-tab applications where a user login causes a JWK set refresh
// due to the key rotation, discarding old keys, and the old tab still keeps the session
// whose signature can only be verified with the now discarded key.
LOG.debugf(
"Session can not be verified due to an unresolved key exception, reauthentication is required");
// Redirect the user to the OIDC provider to re-authenticate
failure = new AuthenticationFailedException();
} else {
// Failures such as the signature verification failures require 401 status
String error = logAuthenticationError(context, t);
failure = t.getCause() instanceof AuthenticationCompletionException
? t.getCause()
: new AuthenticationCompletionException(error, t.getCause());
}

return removeSessionCookie(context, configContext.oidcConfig())
.replaceWith(Uni.createFrom()
.failure(t
.getCause() instanceof AuthenticationCompletionException
? t.getCause()
: new AuthenticationCompletionException(
error, t.getCause())));
.replaceWith(Uni.createFrom().failure(failure));
}
// Token has expired, try to refresh
if (isRpInitiatedLogout(context, configContext)) {
Expand Down

0 comments on commit 674888b

Please sign in to comment.