|
61 | 61 | import org.springframework.security.oauth2.core.AuthorizationGrantType; |
62 | 62 | import org.springframework.security.oauth2.core.ClientAuthenticationMethod; |
63 | 63 | import org.springframework.security.oauth2.core.OAuth2AccessToken; |
| 64 | +import org.springframework.security.oauth2.core.OAuth2ErrorCodes; |
64 | 65 | import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; |
65 | 66 | import org.springframework.security.oauth2.jose.TestJwks; |
66 | 67 | import org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService; |
|
101 | 102 | import org.springframework.security.web.util.matcher.RequestMatcher; |
102 | 103 | import org.springframework.test.web.servlet.MockMvc; |
103 | 104 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; |
| 105 | +import org.springframework.web.util.UriComponentsBuilder; |
104 | 106 |
|
105 | 107 | import static org.assertj.core.api.Assertions.assertThat; |
106 | 108 | import static org.mockito.ArgumentMatchers.any; |
@@ -234,6 +236,37 @@ public void requestWhenTokenRequestPostsClientCredentialsThenTokenResponse() thr |
234 | 236 | verify(jwtCustomizer).customize(any()); |
235 | 237 | } |
236 | 238 |
|
| 239 | + // gh-1378 |
| 240 | + @Test |
| 241 | + public void requestWhenTokenRequestWithClientCredentialsInQueryParamThenInvalidRequest() throws Exception { |
| 242 | + this.spring.register(AuthorizationServerConfiguration.class).autowire(); |
| 243 | + |
| 244 | + RegisteredClient registeredClient = TestRegisteredClients.registeredClient2().build(); |
| 245 | + this.registeredClientRepository.save(registeredClient); |
| 246 | + |
| 247 | + String tokenEndpointUri = UriComponentsBuilder.fromUriString(DEFAULT_TOKEN_ENDPOINT_URI) |
| 248 | + .queryParam(OAuth2ParameterNames.CLIENT_ID, registeredClient.getClientId()) |
| 249 | + .toUriString(); |
| 250 | + |
| 251 | + this.mvc.perform(post(tokenEndpointUri) |
| 252 | + .param(OAuth2ParameterNames.CLIENT_SECRET, registeredClient.getClientSecret()) |
| 253 | + .param(OAuth2ParameterNames.GRANT_TYPE, AuthorizationGrantType.CLIENT_CREDENTIALS.getValue()) |
| 254 | + .param(OAuth2ParameterNames.SCOPE, "scope1 scope2")) |
| 255 | + .andExpect(status().isBadRequest()) |
| 256 | + .andExpect(jsonPath("$.error").value(OAuth2ErrorCodes.INVALID_REQUEST)); |
| 257 | + |
| 258 | + tokenEndpointUri = UriComponentsBuilder.fromUriString(DEFAULT_TOKEN_ENDPOINT_URI) |
| 259 | + .queryParam(OAuth2ParameterNames.CLIENT_SECRET, registeredClient.getClientSecret()) |
| 260 | + .toUriString(); |
| 261 | + |
| 262 | + this.mvc.perform(post(tokenEndpointUri) |
| 263 | + .param(OAuth2ParameterNames.CLIENT_ID, registeredClient.getClientId()) |
| 264 | + .param(OAuth2ParameterNames.GRANT_TYPE, AuthorizationGrantType.CLIENT_CREDENTIALS.getValue()) |
| 265 | + .param(OAuth2ParameterNames.SCOPE, "scope1 scope2")) |
| 266 | + .andExpect(status().isBadRequest()) |
| 267 | + .andExpect(jsonPath("$.error").value(OAuth2ErrorCodes.INVALID_REQUEST)); |
| 268 | + } |
| 269 | + |
237 | 270 | @Test |
238 | 271 | public void requestWhenTokenRequestPostsClientCredentialsAndRequiresUpgradingThenClientSecretUpgraded() throws Exception { |
239 | 272 | this.spring.register(AuthorizationServerConfigurationCustomPasswordEncoder.class).autowire(); |
|
0 commit comments