@@ -94,7 +94,7 @@ public void setUp() {
94
94
// @formatter:on
95
95
this .clientRegistrationRepository = new InMemoryClientRegistrationRepository (this .registration1 ,
96
96
this .registration2 , this .pkceClientRegistration , this .fineRedirectUriTemplateRegistration ,
97
- this .publicClientRegistration , this .oidcRegistration ,nonProofKeyPublicClientRegistration );
97
+ this .publicClientRegistration , this .oidcRegistration , this . nonProofKeyPublicClientRegistration );
98
98
this .resolver = new DefaultOAuth2AuthorizationRequestResolver (this .clientRegistrationRepository ,
99
99
this .authorizationRequestBaseUri );
100
100
}
@@ -175,15 +175,14 @@ public void resolveWhenAuthorizationRequestWithValidClientThenResolves() {
175
175
assertThat (authorizationRequest .getState ()).isNotNull ();
176
176
assertThat (authorizationRequest .getAdditionalParameters ())
177
177
.doesNotContainKey (OAuth2ParameterNames .REGISTRATION_ID );
178
- assertThat (authorizationRequest .getAttributes ())
179
- .containsExactly (
180
- entry (OAuth2ParameterNames .REGISTRATION_ID , clientRegistration .getRegistrationId ()),
181
- entry (PkceParameterNames .CODE_VERIFIER , authorizationRequest .getAttributes ().get (PkceParameterNames .CODE_VERIFIER ))
182
- );
178
+ assertThat (authorizationRequest .getAttributes ()).containsExactly (
179
+ entry (OAuth2ParameterNames .REGISTRATION_ID , clientRegistration .getRegistrationId ()),
180
+ entry (PkceParameterNames .CODE_VERIFIER ,
181
+ authorizationRequest .getAttributes ().get (PkceParameterNames .CODE_VERIFIER )));
183
182
assertThat (authorizationRequest .getAuthorizationRequestUri ())
184
183
.matches ("https://example.com/login/oauth/authorize\\ ?" + "response_type=code&client_id=client-id&"
185
184
+ "scope=read:user&state=.{15,}&"
186
- + "redirect_uri=http://localhost/login/oauth2/code/registration-id&code_challenge=.{15, }&code_challenge_method=S256" );
185
+ + "redirect_uri=http://localhost/login/oauth2/code/registration-id&code_challenge=([a-zA-Z0-9 \\ - \\ . \\ _ \\ ~]){43 }&code_challenge_method=S256" );
187
186
}
188
187
189
188
@ Test
@@ -195,11 +194,10 @@ public void resolveWhenClientAuthorizationRequiredExceptionAvailableThenResolves
195
194
OAuth2AuthorizationRequest authorizationRequest = this .resolver .resolve (request ,
196
195
clientRegistration .getRegistrationId ());
197
196
assertThat (authorizationRequest ).isNotNull ();
198
- assertThat (authorizationRequest .getAttributes ())
199
- .containsExactly (
200
- entry (OAuth2ParameterNames .REGISTRATION_ID , clientRegistration .getRegistrationId ()),
201
- entry (PkceParameterNames .CODE_VERIFIER , authorizationRequest .getAttributes ().get (PkceParameterNames .CODE_VERIFIER ))
202
- );
197
+ assertThat (authorizationRequest .getAttributes ()).containsExactly (
198
+ entry (OAuth2ParameterNames .REGISTRATION_ID , clientRegistration .getRegistrationId ()),
199
+ entry (PkceParameterNames .CODE_VERIFIER ,
200
+ authorizationRequest .getAttributes ().get (PkceParameterNames .CODE_VERIFIER )));
203
201
}
204
202
205
203
@ Test
@@ -307,7 +305,8 @@ public void resolveWhenAuthorizationRequestIncludesPort80ThenExpandedRedirectUri
307
305
assertThat (authorizationRequest .getAuthorizationRequestUri ())
308
306
.matches ("https://example.com/login/oauth/authorize\\ ?" + "response_type=code&client_id=client-id&"
309
307
+ "scope=read:user&state=.{15,}&"
310
- + "redirect_uri=http://localhost/login/oauth2/code/registration-id" + "&code_challenge=.{15,}&code_challenge_method=S256" );
308
+ + "redirect_uri=http://localhost/login/oauth2/code/registration-id"
309
+ + "&code_challenge=([a-zA-Z0-9\\ -\\ .\\ _\\ ~]){43}&code_challenge_method=S256" );
311
310
}
312
311
313
312
@ Test
@@ -323,7 +322,8 @@ public void resolveWhenAuthorizationRequestIncludesPort443ThenExpandedRedirectUr
323
322
assertThat (authorizationRequest .getAuthorizationRequestUri ())
324
323
.matches ("https://example.com/login/oauth/authorize\\ ?" + "response_type=code&client_id=client-id&"
325
324
+ "scope=read:user&state=.{15,}&"
326
- + "redirect_uri=https://example.com/login/oauth2/code/registration-id" + "&code_challenge=.{15,}&code_challenge_method=S256" );
325
+ + "redirect_uri=https://example.com/login/oauth2/code/registration-id"
326
+ + "&code_challenge=([a-zA-Z0-9\\ -\\ .\\ _\\ ~]){43}&code_challenge_method=S256" );
327
327
}
328
328
329
329
@ Test
@@ -337,7 +337,7 @@ public void resolveWhenClientAuthorizationRequiredExceptionAvailableThenRedirect
337
337
assertThat (authorizationRequest .getAuthorizationRequestUri ())
338
338
.matches ("https://example.com/login/oauth/authorize\\ ?" + "response_type=code&client_id=client-id&"
339
339
+ "scope=read:user&state=.{15,}&"
340
- + "redirect_uri=http://localhost/authorize/oauth2/code/registration-id&code_challenge=.{15, }&code_challenge_method=S256" );
340
+ + "redirect_uri=http://localhost/authorize/oauth2/code/registration-id&code_challenge=([a-zA-Z0-9 \\ - \\ . \\ _ \\ ~]){43 }&code_challenge_method=S256" );
341
341
}
342
342
343
343
@ Test
@@ -350,7 +350,8 @@ public void resolveWhenAuthorizationRequestOAuth2LoginThenRedirectUriIsLogin() {
350
350
assertThat (authorizationRequest .getAuthorizationRequestUri ())
351
351
.matches ("https://example.com/login/oauth/authorize\\ ?" + "response_type=code&client_id=client-id-2&"
352
352
+ "scope=read:user&state=.{15,}&"
353
- + "redirect_uri=http://localhost/login/oauth2/code/registration-id-2" + "&code_challenge=.{15,}&code_challenge_method=S256" );
353
+ + "redirect_uri=http://localhost/login/oauth2/code/registration-id-2"
354
+ + "&code_challenge=([a-zA-Z0-9\\ -\\ .\\ _\\ ~]){43}&code_challenge_method=S256" );
354
355
}
355
356
356
357
@ Test
@@ -364,7 +365,8 @@ public void resolveWhenAuthorizationRequestHasActionParameterAuthorizeThenRedire
364
365
assertThat (authorizationRequest .getAuthorizationRequestUri ())
365
366
.matches ("https://example.com/login/oauth/authorize\\ ?" + "response_type=code&client_id=client-id&"
366
367
+ "scope=read:user&state=.{15,}&"
367
- + "redirect_uri=http://localhost/authorize/oauth2/code/registration-id&code_challenge=.{15,}&code_challenge_method=S256" );
368
+ + "redirect_uri=http://localhost/authorize/oauth2/code/registration-id&"
369
+ + "code_challenge=([a-zA-Z0-9\\ -\\ .\\ _\\ ~]){43}&code_challenge_method=S256" );
368
370
}
369
371
370
372
@ Test
@@ -378,7 +380,7 @@ public void resolveWhenAuthorizationRequestHasActionParameterLoginThenRedirectUr
378
380
assertThat (authorizationRequest .getAuthorizationRequestUri ())
379
381
.matches ("https://example.com/login/oauth/authorize\\ ?" + "response_type=code&client_id=client-id-2&"
380
382
+ "scope=read:user&state=.{15,}&"
381
- + "redirect_uri=http://localhost/login/oauth2/code/registration-id-2&code_challenge=.{15, }&code_challenge_method=S256" );
383
+ + "redirect_uri=http://localhost/login/oauth2/code/registration-id-2&code_challenge=([a-zA-Z0-9 \\ - \\ . \\ _ \\ ~]){43 }&code_challenge_method=S256" );
382
384
}
383
385
384
386
@ Test
@@ -447,7 +449,13 @@ public void resolveWhenAuthorizationRequestApplyPkceToConfidentialClientThenAppl
447
449
448
450
@ Test
449
451
public void resolveWhenAuthorizationRequestApplyPkceToPublicClientWithRequireProofKeyFalseThenApplied () {
450
- ClientRegistration clientRegistration = this .nonProofKeyPublicClientRegistration ; // change to non proof key public client
452
+ ClientRegistration clientRegistration = this .nonProofKeyPublicClientRegistration ; // change
453
+ // to
454
+ // non
455
+ // proof
456
+ // key
457
+ // public
458
+ // client
451
459
String requestUri = this .authorizationRequestBaseUri + "/" + clientRegistration .getRegistrationId ();
452
460
MockHttpServletRequest request = new MockHttpServletRequest ("GET" , requestUri );
453
461
OAuth2AuthorizationRequest authorizationRequest = this .resolver .resolve (request );
@@ -511,7 +519,7 @@ public void resolveWhenAuthenticationRequestWithValidOidcClientThenResolves() {
511
519
.matches ("https://example.com/login/oauth/authorize\\ ?" + "response_type=code&client_id=client-id&"
512
520
+ "scope=openid&state=.{15,}&"
513
521
+ "redirect_uri=http://localhost/login/oauth2/code/oidc-registration-id&"
514
- + "nonce=([a-zA-Z0-9\\ -\\ .\\ _\\ ~]){43}&code_challenge=.{15, }&code_challenge_method=S256" );
522
+ + "nonce=([a-zA-Z0-9\\ -\\ .\\ _\\ ~]){43}&code_challenge=([a-zA-Z0-9 \\ - \\ . \\ _ \\ ~]){43 }&code_challenge_method=S256" );
515
523
}
516
524
517
525
// gh-7696
@@ -531,8 +539,8 @@ public void resolveWhenAuthorizationRequestCustomizerRemovesNonceThenQueryExclud
531
539
assertThat (authorizationRequest .getAuthorizationRequestUri ())
532
540
.matches ("https://example.com/login/oauth/authorize\\ ?" + "response_type=code&client_id=client-id&"
533
541
+ "scope=openid&state=.{15,}&"
534
- + "redirect_uri=http://localhost/login/oauth2/code/oidc-registration-id&" +
535
- "code_challenge=.{15, }&code_challenge_method=S256" );
542
+ + "redirect_uri=http://localhost/login/oauth2/code/oidc-registration-id&"
543
+ + "code_challenge=([a-zA-Z0-9 \\ - \\ . \\ _ \\ ~]){43 }&code_challenge_method=S256" );
536
544
}
537
545
538
546
@ Test
@@ -550,7 +558,8 @@ public void resolveWhenAuthorizationRequestCustomizerAddsParameterThenQueryInclu
550
558
.matches ("https://example.com/login/oauth/authorize\\ ?" + "response_type=code&client_id=client-id&"
551
559
+ "scope=openid&state=.{15,}&"
552
560
+ "redirect_uri=http://localhost/login/oauth2/code/oidc-registration-id&"
553
- + "nonce=([a-zA-Z0-9\\ -\\ .\\ _\\ ~]){43}" + "&code_challenge=.{15,}&code_challenge_method=S256¶m1=value1" );
561
+ + "nonce=([a-zA-Z0-9\\ -\\ .\\ _\\ ~]){43}"
562
+ + "&code_challenge=([a-zA-Z0-9\\ -\\ .\\ _\\ ~]){43}&code_challenge_method=S256¶m1=value1" );
554
563
}
555
564
556
565
@ Test
@@ -567,7 +576,8 @@ public void resolveWhenAuthorizationRequestCustomizerOverridesParameterThenQuery
567
576
assertThat (authorizationRequest .getAuthorizationRequestUri ()).matches (
568
577
"https://example.com/login/oauth/authorize\\ ?" + "response_type=code&" + "scope=openid&state=.{15,}&"
569
578
+ "redirect_uri=http://localhost/login/oauth2/code/oidc-registration-id&"
570
- + "nonce=([a-zA-Z0-9\\ -\\ .\\ _\\ ~]){43}" + "&code_challenge=.{15,}&code_challenge_method=S256&appid=client-id" );
579
+ + "nonce=([a-zA-Z0-9\\ -\\ .\\ _\\ ~]){43}"
580
+ + "&code_challenge=([a-zA-Z0-9\\ -\\ .\\ _\\ ~]){43}&code_challenge_method=S256&appid=client-id" );
571
581
}
572
582
573
583
@ Test
@@ -595,6 +605,7 @@ private static ClientRegistration.Builder pkceClientRegistration() {
595
605
.clientId ("client-id-3" )
596
606
.clientSecret ("client-secret" );
597
607
}
608
+
598
609
private static ClientRegistration .Builder fineRedirectUriTemplateClientRegistration () {
599
610
// @formatter:off
600
611
return ClientRegistration .withRegistrationId ("fine-redirect-uri-template-client-registration" )
0 commit comments