Skip to content

Commit

Permalink
Improve the error log and enhancing OAuth2Error
Browse files Browse the repository at this point in the history
  • Loading branch information
leshalv authored Dec 1, 2023
1 parent 068601b commit 52a1e82
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,16 @@ public Authentication authenticate(Authentication authentication) throws Authent
this.logger.warn(LogMessage.format("Invalidated authorization code used by registered client '%s'", registeredClient.getId()));
}
}
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_GRANT);
OAuth2Error error = new OAuth2Error(OAuth2ErrorCodes.INVALID_GRANT,"The authorization code is invalid or has expired.",ERROR_URI);
throw new OAuth2AuthenticationException(error);
}

if (StringUtils.hasText(authorizationRequest.getRedirectUri()) &&
!authorizationRequest.getRedirectUri().equals(authorizationCodeAuthentication.getRedirectUri())) {
if (this.logger.isWarnEnabled()) {
this.logger.warn(LogMessage.format("Invalidated redirect_uri used by registered client '%s'", registeredClient.getId()));
}
OAuth2Error error = new OAuth2Error(OAuth2ErrorCodes.INVALID_GRANT,"The redirect_uri does not match the redirection URI used in the authorization request.",ERROR_URI);
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_GRANT);
}

Expand All @@ -165,7 +170,8 @@ public Authentication authenticate(Authentication authentication) throws Authent
}
}
}
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_GRANT);
OAuth2Error error = new OAuth2Error(OAuth2ErrorCodes.INVALID_GRANT,"The authorization code is invalid or has expired.",ERROR_URI);
throw new OAuth2AuthenticationException(error);
}

if (this.logger.isTraceEnabled()) {
Expand Down

0 comments on commit 52a1e82

Please sign in to comment.