Skip to content

Commit 69b17f3

Browse files
committed
Merge branch '5.8.x' into 6.0.x
Closes gh-13222
2 parents 71703dc + c1002ff commit 69b17f3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/endpoint/DefaultAuthorizationCodeTokenResponseClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,7 +80,10 @@ public OAuth2AccessTokenResponse getTokenResponse(
8080
// If AccessTokenResponse.scope is empty, then we assume all requested scopes were
8181
// granted.
8282
// However, we use the explicit scopes returned in the response (if any).
83-
return response.getBody();
83+
OAuth2AccessTokenResponse tokenResponse = response.getBody();
84+
Assert.notNull(tokenResponse,
85+
"The authorization server responded to this Authorization Code grant request with an empty body; as such, it cannot be materialized into an OAuth2AccessTokenResponse instance. Please check the HTTP response code in your server logs for more details.");
86+
return tokenResponse;
8487
}
8588

8689
private ResponseEntity<OAuth2AccessTokenResponse> getResponse(RequestEntity<?> request) {

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/endpoint/DefaultAuthorizationCodeTokenResponseClientTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -235,6 +235,15 @@ public void getTokenResponseWhenAuthenticationPrivateKeyJwtThenFormParametersAre
235235
assertThat(formParameters).contains("client_assertion=");
236236
}
237237

238+
// gh-13143
239+
@Test
240+
public void getTokenResponseWhenTokenEndpointReturnsEmptyBodyThenIllegalArgument() {
241+
this.server.enqueue(new MockResponse().setResponseCode(302));
242+
ClientRegistration clientRegistration = this.clientRegistration.build();
243+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
244+
() -> this.tokenResponseClient.getTokenResponse(authorizationCodeGrantRequest(clientRegistration)));
245+
}
246+
238247
private void configureJwtClientAuthenticationConverter(Function<ClientRegistration, JWK> jwkResolver) {
239248
NimbusJwtClientAuthenticationParametersConverter<OAuth2AuthorizationCodeGrantRequest> jwtClientAuthenticationConverter = new NimbusJwtClientAuthenticationParametersConverter<>(
240249
jwkResolver);

0 commit comments

Comments
 (0)