|
1 | 1 | /*
|
2 |
| - * Copyright 2020-2023 the original author or authors. |
| 2 | + * Copyright 2020-2024 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.
|
@@ -488,6 +488,35 @@ public void requestWhenConfidentialClientWithPkceAndMissingCodeChallengeThenErro
|
488 | 488 | assertThat(redirectedUrl).isEqualTo(expectedRedirectUri);
|
489 | 489 | }
|
490 | 490 |
|
| 491 | + @Test |
| 492 | + public void requestWhenConfidentialClientWithPkceAndMissingCodeChallengeButCodeVerifierProvidedThenBadRequest() throws Exception { |
| 493 | + this.spring.register(AuthorizationServerConfiguration.class).autowire(); |
| 494 | + |
| 495 | + RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build(); |
| 496 | + this.registeredClientRepository.save(registeredClient); |
| 497 | + |
| 498 | + MultiValueMap<String, String> authorizationRequestParameters = getAuthorizationRequestParameters(registeredClient); |
| 499 | + MvcResult mvcResult = this.mvc.perform(get(DEFAULT_AUTHORIZATION_ENDPOINT_URI) |
| 500 | + .queryParams(authorizationRequestParameters) |
| 501 | + .with(user("user"))) |
| 502 | + .andExpect(status().is3xxRedirection()) |
| 503 | + .andReturn(); |
| 504 | + String redirectedUrl = mvcResult.getResponse().getRedirectedUrl(); |
| 505 | + String expectedRedirectUri = authorizationRequestParameters.getFirst(OAuth2ParameterNames.REDIRECT_URI); |
| 506 | + assertThat(redirectedUrl).matches(expectedRedirectUri + "\\?code=.{15,}&state=" + STATE_URL_ENCODED); |
| 507 | + |
| 508 | + String authorizationCode = extractParameterFromRedirectUri(redirectedUrl, "code"); |
| 509 | + OAuth2Authorization authorizationCodeAuthorization = this.authorizationService.findByToken(authorizationCode, AUTHORIZATION_CODE_TOKEN_TYPE); |
| 510 | + assertThat(authorizationCodeAuthorization).isNotNull(); |
| 511 | + assertThat(authorizationCodeAuthorization.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE); |
| 512 | + |
| 513 | + this.mvc.perform(post(DEFAULT_TOKEN_ENDPOINT_URI) |
| 514 | + .params(getTokenRequestParameters(registeredClient, authorizationCodeAuthorization)) |
| 515 | + .param(PkceParameterNames.CODE_VERIFIER, S256_CODE_VERIFIER) |
| 516 | + .header(HttpHeaders.AUTHORIZATION, getAuthorizationHeader(registeredClient))) |
| 517 | + .andExpect(status().isBadRequest()); |
| 518 | + } |
| 519 | + |
491 | 520 | @Test
|
492 | 521 | public void requestWhenCustomTokenGeneratorThenUsed() throws Exception {
|
493 | 522 | this.spring.register(AuthorizationServerConfigurationWithTokenGenerator.class).autowire();
|
|
0 commit comments