mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-25 13:32:30 +00:00
Fixed validation in ClientRegistration.Builder
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
This commit is contained in:
parent
57bc456ad6
commit
e7588fb32f
@ -486,7 +486,7 @@ public final class ClientRegistration implements Serializable {
|
||||
this.validateClientCredentialsGrantType();
|
||||
} else if (AuthorizationGrantType.IMPLICIT.equals(this.authorizationGrantType)) {
|
||||
this.validateImplicitGrantType();
|
||||
} else {
|
||||
} else if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(this.authorizationGrantType)) {
|
||||
this.validateAuthorizationCodeGrantType();
|
||||
}
|
||||
return this.create();
|
||||
|
@ -535,4 +535,27 @@ public class ClientRegistrationTests {
|
||||
.build()
|
||||
).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildWhenCustomGrantAllAttributesProvidedThenAllAttributesAreSet() {
|
||||
AuthorizationGrantType customGrantType = new AuthorizationGrantType("CUSTOM");
|
||||
ClientRegistration registration = ClientRegistration.withRegistrationId(REGISTRATION_ID)
|
||||
.clientId(CLIENT_ID)
|
||||
.clientSecret(CLIENT_SECRET)
|
||||
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
|
||||
.authorizationGrantType(customGrantType)
|
||||
.scope(SCOPES.toArray(new String[0]))
|
||||
.tokenUri(TOKEN_URI)
|
||||
.clientName(CLIENT_NAME)
|
||||
.build();
|
||||
|
||||
assertThat(registration.getRegistrationId()).isEqualTo(REGISTRATION_ID);
|
||||
assertThat(registration.getClientId()).isEqualTo(CLIENT_ID);
|
||||
assertThat(registration.getClientSecret()).isEqualTo(CLIENT_SECRET);
|
||||
assertThat(registration.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.BASIC);
|
||||
assertThat(registration.getAuthorizationGrantType()).isEqualTo(customGrantType);
|
||||
assertThat(registration.getScopes()).isEqualTo(SCOPES);
|
||||
assertThat(registration.getProviderDetails().getTokenUri()).isEqualTo(TOKEN_URI);
|
||||
assertThat(registration.getClientName()).isEqualTo(CLIENT_NAME);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user