|
1 | 1 | /* |
2 | | - * Copyright 2020-2022 the original author or authors. |
| 2 | + * Copyright 2020-2023 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
60 | 60 | import org.springframework.security.oauth2.core.AuthorizationGrantType; |
61 | 61 | import org.springframework.security.oauth2.core.ClientAuthenticationMethod; |
62 | 62 | import org.springframework.security.oauth2.core.OAuth2AccessToken; |
| 63 | +import org.springframework.security.oauth2.core.OAuth2ErrorCodes; |
63 | 64 | import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; |
64 | 65 | import org.springframework.security.oauth2.jose.TestJwks; |
65 | 66 | import org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService; |
|
98 | 99 | import org.springframework.security.web.util.matcher.RequestMatcher; |
99 | 100 | import org.springframework.test.web.servlet.MockMvc; |
100 | 101 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; |
| 102 | +import org.springframework.web.util.UriComponentsBuilder; |
101 | 103 |
|
102 | 104 | import static org.assertj.core.api.Assertions.assertThat; |
103 | 105 | import static org.mockito.ArgumentMatchers.any; |
@@ -231,6 +233,37 @@ public void requestWhenTokenRequestPostsClientCredentialsThenTokenResponse() thr |
231 | 233 | verify(jwtCustomizer).customize(any()); |
232 | 234 | } |
233 | 235 |
|
| 236 | + // gh-1378 |
| 237 | + @Test |
| 238 | + public void requestWhenTokenRequestWithClientCredentialsInQueryParamThenInvalidRequest() throws Exception { |
| 239 | + this.spring.register(AuthorizationServerConfiguration.class).autowire(); |
| 240 | + |
| 241 | + RegisteredClient registeredClient = TestRegisteredClients.registeredClient2().build(); |
| 242 | + this.registeredClientRepository.save(registeredClient); |
| 243 | + |
| 244 | + String tokenEndpointUri = UriComponentsBuilder.fromUriString(DEFAULT_TOKEN_ENDPOINT_URI) |
| 245 | + .queryParam(OAuth2ParameterNames.CLIENT_ID, registeredClient.getClientId()) |
| 246 | + .toUriString(); |
| 247 | + |
| 248 | + this.mvc.perform(post(tokenEndpointUri) |
| 249 | + .param(OAuth2ParameterNames.CLIENT_SECRET, registeredClient.getClientSecret()) |
| 250 | + .param(OAuth2ParameterNames.GRANT_TYPE, AuthorizationGrantType.CLIENT_CREDENTIALS.getValue()) |
| 251 | + .param(OAuth2ParameterNames.SCOPE, "scope1 scope2")) |
| 252 | + .andExpect(status().isBadRequest()) |
| 253 | + .andExpect(jsonPath("$.error").value(OAuth2ErrorCodes.INVALID_REQUEST)); |
| 254 | + |
| 255 | + tokenEndpointUri = UriComponentsBuilder.fromUriString(DEFAULT_TOKEN_ENDPOINT_URI) |
| 256 | + .queryParam(OAuth2ParameterNames.CLIENT_SECRET, registeredClient.getClientSecret()) |
| 257 | + .toUriString(); |
| 258 | + |
| 259 | + this.mvc.perform(post(tokenEndpointUri) |
| 260 | + .param(OAuth2ParameterNames.CLIENT_ID, registeredClient.getClientId()) |
| 261 | + .param(OAuth2ParameterNames.GRANT_TYPE, AuthorizationGrantType.CLIENT_CREDENTIALS.getValue()) |
| 262 | + .param(OAuth2ParameterNames.SCOPE, "scope1 scope2")) |
| 263 | + .andExpect(status().isBadRequest()) |
| 264 | + .andExpect(jsonPath("$.error").value(OAuth2ErrorCodes.INVALID_REQUEST)); |
| 265 | + } |
| 266 | + |
234 | 267 | @Test |
235 | 268 | public void requestWhenTokenEndpointCustomizedThenUsed() throws Exception { |
236 | 269 | this.spring.register(AuthorizationServerConfigurationCustomTokenEndpoint.class).autowire(); |
|
0 commit comments