Skip to content

Commit a9a9c2c

Browse files
Martin Nemecjgrandja
Martin Nemec
authored andcommitted
OAuth2 ClientRegistrations NPE fix when userinfo missing
Fixes gh-8187
1 parent cb7786b commit a9a9c2c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,12 @@ private static Supplier<ClientRegistration.Builder> oidc(URI issuer) {
146146
RequestEntity<Void> request = RequestEntity.get(uri).build();
147147
Map<String, Object> configuration = rest.exchange(request, typeReference).getBody();
148148
OIDCProviderMetadata metadata = parse(configuration, OIDCProviderMetadata::parse);
149-
return withProviderConfiguration(metadata, issuer.toASCIIString())
150-
.jwkSetUri(metadata.getJWKSetURI().toASCIIString())
151-
.userInfoUri(metadata.getUserInfoEndpointURI().toASCIIString());
149+
ClientRegistration.Builder builder = withProviderConfiguration(metadata, issuer.toASCIIString())
150+
.jwkSetUri(metadata.getJWKSetURI().toASCIIString());
151+
if (metadata.getUserInfoEndpointURI() != null) {
152+
builder.userInfoUri(metadata.getUserInfoEndpointURI().toASCIIString());
153+
}
154+
return builder;
152155
};
153156
}
154157

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

+8
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ public void issuerWhenOAuth2ResponseMissingJwksUriThenThenSuccess() throws Excep
195195
assertThat(provider.getJwkSetUri()).isNull();
196196
}
197197

198+
// gh-8187
199+
@Test
200+
public void issuerWhenResponseMissingUserInfoUriThenSuccess() throws Exception {
201+
this.response.remove("userinfo_endpoint");
202+
ClientRegistration registration = registration("").build();
203+
assertThat(registration.getProviderDetails().getUserInfoEndpoint().getUri()).isNull();
204+
}
205+
198206
@Test
199207
public void issuerWhenContainsTrailingSlashThenSuccess() throws Exception {
200208
assertThat(registration("")).isNotNull();

0 commit comments

Comments
 (0)