|
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.
|
@@ -540,6 +540,35 @@ public void requestWhenConfidentialClientWithPkceAndMissingCodeChallengeThenErro
|
540 | 540 | assertThat(redirectedUrl).isEqualTo(expectedRedirectUri);
|
541 | 541 | }
|
542 | 542 |
|
| 543 | + @Test |
| 544 | + public void requestWhenConfidentialClientWithPkceAndMissingCodeChallengeButCodeVerifierProvidedThenBadRequest() throws Exception { |
| 545 | + this.spring.register(AuthorizationServerConfiguration.class).autowire(); |
| 546 | + |
| 547 | + RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build(); |
| 548 | + this.registeredClientRepository.save(registeredClient); |
| 549 | + |
| 550 | + MultiValueMap<String, String> authorizationRequestParameters = getAuthorizationRequestParameters(registeredClient); |
| 551 | + MvcResult mvcResult = this.mvc.perform(get(DEFAULT_AUTHORIZATION_ENDPOINT_URI) |
| 552 | + .queryParams(authorizationRequestParameters) |
| 553 | + .with(user("user"))) |
| 554 | + .andExpect(status().is3xxRedirection()) |
| 555 | + .andReturn(); |
| 556 | + String redirectedUrl = mvcResult.getResponse().getRedirectedUrl(); |
| 557 | + String expectedRedirectUri = authorizationRequestParameters.getFirst(OAuth2ParameterNames.REDIRECT_URI); |
| 558 | + assertThat(redirectedUrl).matches(expectedRedirectUri + "\\?code=.{15,}&state=" + STATE_URL_ENCODED); |
| 559 | + |
| 560 | + String authorizationCode = extractParameterFromRedirectUri(redirectedUrl, "code"); |
| 561 | + OAuth2Authorization authorizationCodeAuthorization = this.authorizationService.findByToken(authorizationCode, AUTHORIZATION_CODE_TOKEN_TYPE); |
| 562 | + assertThat(authorizationCodeAuthorization).isNotNull(); |
| 563 | + assertThat(authorizationCodeAuthorization.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE); |
| 564 | + |
| 565 | + this.mvc.perform(post(DEFAULT_TOKEN_ENDPOINT_URI) |
| 566 | + .params(getTokenRequestParameters(registeredClient, authorizationCodeAuthorization)) |
| 567 | + .param(PkceParameterNames.CODE_VERIFIER, S256_CODE_VERIFIER) |
| 568 | + .header(HttpHeaders.AUTHORIZATION, getAuthorizationHeader(registeredClient))) |
| 569 | + .andExpect(status().isBadRequest()); |
| 570 | + } |
| 571 | + |
543 | 572 | @Test
|
544 | 573 | public void requestWhenCustomTokenGeneratorThenUsed() throws Exception {
|
545 | 574 | this.spring.register(AuthorizationServerConfigurationWithTokenGenerator.class).autowire();
|
|
0 commit comments