-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Refactor auth token/login providers #7356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
pdelert
commented
Sep 4, 2019
- OAuth2AuthorizationCodeAuthenticationToken uses OAuth2LoginAuthenticationToken
- OAuth2LoginAuthenticationProvider uses OAuth2AuthorizationCodeAuthenticationProvider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @pdelert. I left some feedback for you.
@@ -39,11 +39,9 @@ | |||
* @see OAuth2AccessToken | |||
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-4.1">Section 4.1 Authorization Code Grant Flow</a> | |||
*/ | |||
public class OAuth2AuthorizationCodeAuthenticationToken extends AbstractAuthenticationToken { | |||
public class OAuth2AuthorizationCodeAuthenticationToken extends OAuth2LoginAuthenticationToken { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposed update should be OAuth2LoginAuthenticationToken extends OAuth2AuthorizationCodeAuthenticationToken
. Please see comment.
OAuth2LoginAuthenticationProvider
implements authorization_code
grant flow on top of OpenID Connect, so it's logical for OAuth2LoginAuthenticationToken
to extend OAuth2AuthorizationCodeAuthenticationToken
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments applied on code
* | ||
* @return the {@link ClientRegistration} | ||
*/ | ||
public ClientRegistration getClientRegistration() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change for a patch release. Please see Semantic versioning for more details.
@@ -59,8 +59,7 @@ | |||
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-4.1.3">Section 4.1.3 Access Token Request</a> | |||
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-4.1.4">Section 4.1.4 Access Token Response</a> | |||
*/ | |||
public class OAuth2LoginAuthenticationProvider implements AuthenticationProvider { | |||
private final OAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> accessTokenResponseClient; | |||
public class OAuth2LoginAuthenticationProvider extends OAuth2AuthorizationCodeAuthenticationProvider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The preference is that OAuth2LoginAuthenticationProvider
uses OAuth2AuthorizationCodeAuthenticationProvider
as a collaborator (composition) instead of through extension. Similar to how OAuth2LoginReactiveAuthenticationManager
uses OAuth2AuthorizationCodeReactiveAuthenticationManager
internally.
@@ -118,7 +118,7 @@ public OAuth2LoginAuthenticationToken(ClientRegistration clientRegistration, | |||
} | |||
|
|||
@Override | |||
public OAuth2User getPrincipal() { | |||
public Object getPrincipal() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not need to be changed.
* OAuth2LoginAuthenticationToken uses OAuth2AuthorizationCodeAuthenticationToken * OAuth2LoginAuthenticationProvider uses OAuth2AuthorizationCodeAuthenticationProvider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @pdelert. Please see comments
@@ -83,4 +83,8 @@ public Authentication authenticate(Authentication authentication) throws Authent | |||
public boolean supports(Class<?> authentication) { | |||
return OAuth2AuthorizationCodeAuthenticationToken.class.isAssignableFrom(authentication); | |||
} | |||
|
|||
public OAuth2AccessTokenResponse getAccessTokenResponse(OAuth2AuthorizationCodeGrantRequest oAuth2AuthorizationCodeGrantRequest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change cannot go into a patch release as this is targeted for 5.1.x. Please review the acceptable changes for patch, minor and major.
authorizationCodeAuthentication.getClientRegistration(), | ||
authorizationCodeAuthentication.getAuthorizationExchange())); | ||
accessTokenResponse = ((OAuth2AuthorizationCodeAuthenticationProvider) this.authenticationProvider) | ||
.getAccessTokenResponse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead call OAuth2AuthorizationCodeAuthenticationProvider.authenticate()
private OAuth2AuthorizationExchange authorizationExchange; | ||
private OAuth2AccessToken accessToken; | ||
private OAuth2RefreshToken refreshToken; | ||
private OAuth2AuthorizationCodeAuthenticationToken oAuth2AuthorizationCodeAuthenticationToken; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of composition use inheritance OAuth2LoginAuthenticationToken extends OAuth2AuthorizationCodeAuthenticationToken
as noted in this comment
@pdelert Have you had time to apply the latest changes? |