-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Implement Client Credentials Authentication #72
Conversation
@jgrandja Few questions:
|
.../security/oauth2/server/authorization/authentication/OAuth2ClientAuthenticationProvider.java
Outdated
Show resolved
Hide resolved
.../security/oauth2/server/authorization/authentication/OAuth2ClientAuthenticationProvider.java
Show resolved
Hide resolved
.../springframework/security/oauth2/server/authorization/web/ClientAuthenticationConverter.java
Outdated
Show resolved
Hide resolved
.../security/oauth2/server/authorization/authentication/OAuth2ClientAuthenticationProvider.java
Outdated
Show resolved
Hide resolved
...ringframework/security/oauth2/server/authorization/web/OAuth2ClientAuthenticationFilter.java
Outdated
Show resolved
Hide resolved
@jgrandja Could you please elaborate?
Isn't |
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 @pkostrzewa. Please see my review comments.
.../security/oauth2/server/authorization/authentication/OAuth2ClientAuthenticationProvider.java
Outdated
Show resolved
Hide resolved
.../security/oauth2/server/authorization/authentication/OAuth2ClientAuthenticationProvider.java
Outdated
Show resolved
Hide resolved
.../security/oauth2/server/authorization/authentication/OAuth2ClientAuthenticationProvider.java
Outdated
Show resolved
Hide resolved
...ork/security/oauth2/server/authorization/authentication/OAuth2ClientAuthenticationToken.java
Outdated
Show resolved
Hide resolved
.../security/oauth2/server/authorization/authentication/OAuth2ClientAuthenticationProvider.java
Outdated
Show resolved
Hide resolved
...ringframework/security/oauth2/server/authorization/web/OAuth2ClientAuthenticationFilter.java
Outdated
Show resolved
Hide resolved
...ringframework/security/oauth2/server/authorization/web/OAuth2ClientAuthenticationFilter.java
Show resolved
Hide resolved
.../springframework/security/oauth2/server/authorization/web/ClientAuthenticationConverter.java
Outdated
Show resolved
Hide resolved
.../springframework/security/oauth2/server/authorization/web/ClientAuthenticationConverter.java
Outdated
Show resolved
Hide resolved
.../springframework/security/oauth2/server/authorization/web/ClientAuthenticationConverter.java
Outdated
Show resolved
Hide resolved
Yes, it will be in a later story. Nothing to do as far as this issue goes. I was simply stating the runtime expectations. I updated the main issue to be clear. |
Thanks for the review! I will update the PR with your comments later on today. |
@jgrandja I've updated the PR. There are still missing tests and documentation and I will provide both as soon as I can. |
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 @pkostrzewa. Please see my review comments.
For the next update, can you please rebase on master
and avoid merge commits. And after you add all the tests please change the Draft to Ready and I think we'll be close to merging.
...ringframework/security/oauth2/server/authorization/web/OAuth2ClientAuthenticationFilter.java
Outdated
Show resolved
Hide resolved
...ringframework/security/oauth2/server/authorization/web/OAuth2ClientAuthenticationFilter.java
Outdated
Show resolved
Hide resolved
...ringframework/security/oauth2/server/authorization/web/OAuth2ClientAuthenticationFilter.java
Show resolved
Hide resolved
...ringframework/security/oauth2/server/authorization/web/OAuth2ClientAuthenticationFilter.java
Outdated
Show resolved
Hide resolved
...gframework/security/oauth2/server/authorization/web/OAuth2ClientAuthenticationConverter.java
Outdated
Show resolved
Hide resolved
...th2/server/authorization/authentication/DefaultOAuth2ClientAuthenticationSuccessHandler.java
Outdated
Show resolved
Hide resolved
...th2/server/authorization/authentication/DefaultOAuth2ClientAuthenticationFailureHandler.java
Outdated
Show resolved
Hide resolved
...th2/server/authorization/authentication/DefaultOAuth2ClientAuthenticationFailureHandler.java
Outdated
Show resolved
Hide resolved
...ework/security/oauth2/server/authorization/web/OAuth2ClientAuthenticationConverterTests.java
Outdated
Show resolved
Hide resolved
Thanks for the review @jgrandja. I will update the PR soon. |
Do you mean I should squash all commits from this PR into single one? |
@pkostrzewa Yes please squash to 1 commit and rebase on latest master. |
I've added missing tests and rebased on top of the If there will be any changes requested I can address them next wednesday at earliest. |
if (credentials.length != 2) { | ||
throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.INVALID_TOKEN)); | ||
} | ||
return new OAuth2ClientAuthenticationToken(credentials[0], credentials[1]); |
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.
@pkostrzewa cc: @jgrandja
As per RFC 6749 - section 2.3.1, the client identifier and client password are further encoded using application/x-www-form-urlencoded
encoding algorithm and then used as username and password in HTTP Basic Authentication Scheme.
The client identifier is encoded using the
"application/x-www-form-urlencoded" encoding algorithm per
Appendix B, and the encoded value is used as the username; the client
password is encoded using the same algorithm and used as the
password.
There is an issue already logged in legacy oauth2 project spring-attic/spring-security-oauth#1826 and we should implement this according to specification in this project.
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.
@anoopgarlapati
Although RFC 6749 - section 2.3.1, indeed does say:
The client identifier is encoded using the
"application/x-www-form-urlencoded" encoding algorithm per
Appendix B, and the encoded value is used as the username; the client
password is encoded using the same algorithm and used as the
password.
It further states:
Including the client credentials in the request-body using the two parameters is NOT RECOMMENDED and SHOULD be limited to clients unable to directly utilize the HTTP Basic authentication scheme (or other password-based HTTP authentication schemes). the parameters can only be transmitted in the request-body and MUST NOT be included in the request URI.
The authorization server MUST require the of TLS as described in Section 1.6 when sending requests using password authentication.
Since this client authentication method involves a password, the authorization server MUST protect any endpoint utilizing it against brute force attacks.
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.
Those sections do not contradict each other. The encoding needs to be applied when using Basic authentication.
Thank you for all the updates @pkostrzewa ! Overall, the implementation looked good, however, I did add a polish commit in order to get this merged. Please take a look at the changes applied in the polish commit and let me know if you have any questions. Thank you again and I look forward to another contribution 👍 |
Filter
should process requests for the (default) path/oauth2/token
and check if credentials are available in the request.OAuth2ClientAuthenticationToken
should be passed to theAuthenticationManager
.AuthenticationManager
should be composed ofOAuth2ClientAuthenticationProvider
.OAuth2ClientAuthenticationProvider
should use theRegisteredClientRepository
.RegisteredClient
should be returned in a newOAuth2ClientAuthenticationToken
if the authentication succeeds.Filter
should save theOAuth2ClientAuthenticationToken
in theSecurityContext
.class
andpublic
methods.The
ClientAuthenticationConverter
is based onBasicAuthenticationFilter
.Fixes #39 .