Skip to content

Commit 0486d5a

Browse files
martin-vjgrandja
authored andcommitted
scopes_supported metadata not used as default in ClientRegistrations
Closes gh-8514
1 parent 21e9a41 commit 0486d5a

File tree

3 files changed

+2
-51
lines changed

3 files changed

+2
-51
lines changed

config/src/test/java/org/springframework/security/config/oauth2/client/ClientRegistrationsBeanDefinitionParserTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void parseWhenIssuerUriConfiguredThenRequestConfigFromIssuer() throws Exc
152152
assertThat(googleRegistration.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.BASIC);
153153
assertThat(googleRegistration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
154154
assertThat(googleRegistration.getRedirectUri()).isEqualTo("{baseUrl}/{action}/oauth2/code/{registrationId}");
155-
assertThat(googleRegistration.getScopes()).isEqualTo(StringUtils.commaDelimitedListToSet("openid,profile,email"));
155+
assertThat(googleRegistration.getScopes()).isNull();
156156
assertThat(googleRegistration.getClientName()).isEqualTo(serverUrl);
157157

158158
ProviderDetails googleProviderDetails = googleRegistration.getProviderDetails();

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

-14
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import com.nimbusds.oauth2.sdk.GrantType;
2727
import com.nimbusds.oauth2.sdk.ParseException;
28-
import com.nimbusds.oauth2.sdk.Scope;
2928
import com.nimbusds.oauth2.sdk.as.AuthorizationServerMetadata;
3029
import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata;
3130
import net.minidev.json.JSONObject;
@@ -35,7 +34,6 @@
3534
import org.springframework.security.oauth2.core.AuthorizationGrantType;
3635
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
3736
import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames;
38-
import org.springframework.security.oauth2.core.oidc.OidcScopes;
3937
import org.springframework.util.Assert;
4038
import org.springframework.web.client.HttpClientErrorException;
4139
import org.springframework.web.client.RestTemplate;
@@ -236,12 +234,10 @@ private static ClientRegistration.Builder withProviderConfiguration(Authorizatio
236234
throw new IllegalArgumentException("Only AuthorizationGrantType.AUTHORIZATION_CODE is supported. The issuer \"" + issuer +
237235
"\" returned a configuration of " + grantTypes);
238236
}
239-
List<String> scopes = getScopes(metadata);
240237
Map<String, Object> configurationMetadata = new LinkedHashMap<>(metadata.toJSONObject());
241238

242239
return ClientRegistration.withRegistrationId(name)
243240
.userNameAttributeName(IdTokenClaimNames.SUB)
244-
.scope(scopes)
245241
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
246242
.clientAuthenticationMethod(method)
247243
.redirectUri("{baseUrl}/{action}/oauth2/code/{registrationId}")
@@ -268,16 +264,6 @@ private static ClientAuthenticationMethod getClientAuthenticationMethod(String i
268264
+ "ClientAuthenticationMethod.NONE are supported. The issuer \"" + issuer + "\" returned a configuration of " + metadataAuthMethods);
269265
}
270266

271-
private static List<String> getScopes(AuthorizationServerMetadata metadata) {
272-
Scope scope = metadata.getScopes();
273-
if (scope == null) {
274-
// If null, default to "openid" which must be supported
275-
return Collections.singletonList(OidcScopes.OPENID);
276-
} else {
277-
return scope.toStringList();
278-
}
279-
}
280-
281267
private ClientRegistrations() {}
282268

283269
}

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

+1-36
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private void assertIssuerMetadata(ClientRegistration registration,
158158
assertThat(registration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
159159
assertThat(registration.getRegistrationId()).isEqualTo(this.server.getHostName());
160160
assertThat(registration.getClientName()).isEqualTo(this.issuer);
161-
assertThat(registration.getScopes()).containsOnly("openid", "email", "profile");
161+
assertThat(registration.getScopes()).isNull();
162162
assertThat(provider.getAuthorizationUri()).isEqualTo("https://example.com/o/oauth2/v2/auth");
163163
assertThat(provider.getTokenUri()).isEqualTo("https://example.com/oauth2/v4/token");
164164
assertThat(provider.getJwkSetUri()).isEqualTo("https://example.com/oauth2/v3/certs");
@@ -222,41 +222,6 @@ public void issuerWhenOAuth2ContainsTrailingSlashThenSuccess() throws Exception
222222
assertThat(this.issuer).endsWith("/");
223223
}
224224

225-
/**
226-
* https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
227-
*
228-
* RECOMMENDED. JSON array containing a list of the OAuth 2.0 [RFC6749] scope values that this server supports. The
229-
* server MUST support the openid scope value.
230-
* @throws Exception
231-
*/
232-
@Test
233-
public void issuerWhenScopesNullThenScopesDefaulted() throws Exception {
234-
this.response.remove("scopes_supported");
235-
236-
ClientRegistration registration = registration("").build();
237-
238-
assertThat(registration.getScopes()).containsOnly("openid");
239-
}
240-
241-
@Test
242-
public void issuerWhenOidcFallbackScopesNullThenScopesDefaulted() throws Exception {
243-
this.response.remove("scopes_supported");
244-
245-
ClientRegistration registration = registrationOidcFallback("", null).build();
246-
247-
assertThat(registration.getScopes()).containsOnly("openid");
248-
}
249-
250-
@Test
251-
public void issuerWhenOAuth2ScopesNullThenScopesDefaulted() throws Exception {
252-
this.response.remove("scopes_supported");
253-
254-
ClientRegistration registration = registrationOAuth2("", null).build();
255-
256-
assertThat(registration.getScopes()).containsOnly("openid");
257-
}
258-
259-
260225
@Test
261226
public void issuerWhenGrantTypesSupportedNullThenDefaulted() throws Exception {
262227
this.response.remove("grant_types_supported");

0 commit comments

Comments
 (0)