Skip to content

Commit 1544191

Browse files
Steve RiesenbergAyush Kohli
Steve Riesenberg
authored and
Ayush Kohli
committed
Remove validation for unsupported grant types
Closes spring-projectsgh-9828
1 parent 443833d commit 1544191

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/registration/ClientRegistrations.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.Map;
2424
import java.util.function.Supplier;
2525

26-
import com.nimbusds.oauth2.sdk.GrantType;
2726
import com.nimbusds.oauth2.sdk.ParseException;
2827
import com.nimbusds.oauth2.sdk.as.AuthorizationServerMetadata;
2928
import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata;
@@ -242,13 +241,6 @@ private static ClientRegistration.Builder withProviderConfiguration(Authorizatio
242241
String name = URI.create(issuer).getHost();
243242
ClientAuthenticationMethod method = getClientAuthenticationMethod(issuer,
244243
metadata.getTokenEndpointAuthMethods());
245-
List<GrantType> grantTypes = metadata.getGrantTypes();
246-
// If null, the default includes authorization_code
247-
if (grantTypes != null && !grantTypes.contains(GrantType.AUTHORIZATION_CODE)) {
248-
throw new IllegalArgumentException(
249-
"Only AuthorizationGrantType.AUTHORIZATION_CODE is supported. The issuer \"" + issuer
250-
+ "\" returned a configuration of " + grantTypes);
251-
}
252244
Map<String, Object> configurationMetadata = new LinkedHashMap<>(metadata.toJSONObject());
253245
// @formatter:off
254246
return ClientRegistration.withRegistrationId(name)

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/registration/ClientRegistrationsTests.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,24 +240,22 @@ public void issuerWhenOAuth2GrantTypesSupportedNullThenDefaulted() throws Except
240240
assertThat(registration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
241241
}
242242

243-
/**
244-
* We currently only support authorization_code, so verify we have a meaningful error
245-
* until we add support.
246-
*/
243+
// gh-9828
247244
@Test
248-
public void issuerWhenGrantTypesSupportedInvalidThenException() {
245+
public void issuerWhenImplicitGrantTypeThenSuccess() throws Exception {
249246
this.response.put("grant_types_supported", Arrays.asList("implicit"));
250-
assertThatIllegalArgumentException().isThrownBy(() -> registration(""))
251-
.withMessageContaining("Only AuthorizationGrantType.AUTHORIZATION_CODE is supported. The issuer \""
252-
+ this.issuer + "\" returned a configuration of [implicit]");
247+
ClientRegistration registration = registration("").build();
248+
// The authorization_code grant type is still the default
249+
assertThat(registration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
253250
}
254251

252+
// gh-9828
255253
@Test
256-
public void issuerWhenOAuth2GrantTypesSupportedInvalidThenException() {
257-
this.response.put("grant_types_supported", Arrays.asList("implicit"));
258-
assertThatIllegalArgumentException().isThrownBy(() -> registrationOAuth2("", null))
259-
.withMessageContaining("Only AuthorizationGrantType.AUTHORIZATION_CODE is supported. The issuer \""
260-
+ this.issuer + "\" returned a configuration of [implicit]");
254+
public void issuerWhenOAuth2JwtBearerGrantTypeThenSuccess() throws Exception {
255+
this.response.put("grant_types_supported", Arrays.asList("urn:ietf:params:oauth:grant-type:jwt-bearer"));
256+
ClientRegistration registration = registrationOAuth2("", null).build();
257+
// The authorization_code grant type is still the default
258+
assertThat(registration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
261259
}
262260

263261
@Test

0 commit comments

Comments
 (0)