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