-
Notifications
You must be signed in to change notification settings - Fork 6k
Can't use a custom authorization grant type in a ClientRegistration #7040
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
Comments
@edouardhue Specifying a custom grant using I'm going to close this ticket as invalid. If you're looking for a specific |
Hi @jgrandja, I am currently migrating from Spring Security 4 to 5 and I can't port my code. I had implemented a custom grant type, on both authorization and resource server sides. The Javadoc in https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/oauth2/core/AuthorizationGrantType.html clearly states that "The OAuth 2.0 Authorization Framework defines four standard grant types: authorization code, implicit, resource owner password credentials, and client credentials. It also provides an extensibility mechanism for defining additional grant types." AuthorizationGrantType's constructor is public, custom types may be defined in Spring Security 5. The default validation I pointed out in the ClientRegistration builder is the only point that won't allow a custom grant type to be used by a client. Looks like a violation of the open-closed principle to me! |
The new OAuth support was introduced in Spring Security 5. So I'm confused as to what you are porting since it wasn't available in Spring Security 4?
Authorization Grants are implemented between the Client and Authorization Server NOT Resource Server. The Resource Server just receives the access token. It's still not clear to me what you are trying to accomplish. Can you please be more specific with details so I can better understand. |
Sorry for my too quick answer yesterday, allow me to correct myself. I indeed meant client instead of resource server.
I used the spring-security-oauth subproject with Spring Security 4 (all under Spring Boot 1.5).
For very specific reasons, I need to define a custom grant type carrying some custom credentials that can't fit into the standard grant types. On the client side, I only had to implement a custom When migrating to Spring Security 5 native support, I extended I ask for this method to be changed to allow for extension: public ClientRegistration build() {
Assert.notNull(this.authorizationGrantType, "authorizationGrantType cannot be null");
if (AuthorizationGrantType.CLIENT_CREDENTIALS.equals(this.authorizationGrantType)) {
this.validateClientCredentialsGrantType();
} else if (AuthorizationGrantType.IMPLICIT.equals(this.authorizationGrantType)) {
this.validateImplicitGrantType();
} else if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(this.authorizationGrantType)) {
this.validateAuthorizationCodeGrantType();
}
return this.create();
} Maybe a validation function could be passed to Making the |
Thank you for the explanation @edouardhue. I now understand how you are porting your code and the issue you are having with the FYI, I would recommend tracking the work in #6811 as it will help with creating a custom grant for the client with the introduction of the |
Thanks for reopening the issue. I'll submit a PR soon. |
There it is: #7047 |
ClientRegistration.Builder defaulted to validating as an authorization_code registration, though a custom grant type could be in use. The actual grant_type is now verified for every case. - Fixed validation in ClientRegistration.Builder - New test that fails unless the issue is fixed. Also made OAuth2AuthorizationGrantRequestEntityUtils public to help implementing custom token response clients. Fixes spring-projectsgh-7040
ClientRegistration.Builder defaulted to validating as an authorization_code registration, though a custom grant type could be in use. The actual grant_type is now verified for every case. - Fixed validation in ClientRegistration.Builder - New test that fails unless the issue is fixed. Also made OAuth2AuthorizationGrantRequestEntityUtils public to help implementing custom token response clients. Fixes gh-7040
ClientRegistration.Builder defaulted to validating as an authorization_code registration, though a custom grant type could be in use. The actual grant_type is now verified for every case. - Fixed validation in ClientRegistration.Builder - New test that fails unless the issue is fixed. Also made OAuth2AuthorizationGrantRequestEntityUtils public to help implementing custom token response clients. Fixes gh-7040
ClientRegistration.Builder defaulted to validating as an authorization_code registration, though a custom grant type could be in use. The actual grant_type is now verified for every case. - Fixed validation in ClientRegistration.Builder - New test that fails unless the issue is fixed. Also made OAuth2AuthorizationGrantRequestEntityUtils public to help implementing custom token response clients. Fixes spring-projectsgh-7040
Uh oh!
There was an error while loading. Please reload this page.
Summary
Documentation suggests that defining additional grant types should be supported. Though, the ClientRegistration builder won't validate a registration using a custom grant type.
Actual Behavior
org.springframework.security.oauth2.core.AuthorizationGrantType
.org.springframework.security.oauth2.client.registration.ClientRegistration
with this custom type.When calling
build()
, any unsupported grant type is validated as an authorization code grant type, and it fails.Expected Behavior
Custom grant type should not be validated with the wrong validator. It could be nice to be able to provide a custom validator.
Version
spring-security-oauth2-client 5.1.5.RELEASE
Sample
The text was updated successfully, but these errors were encountered: