@@ -528,8 +528,6 @@ protected UriBuilder createAuthorizationUrl(AuthenticationRequest request) {
528528 uriBuilder .queryParam (OAuth2Constants .PROMPT , prompt );
529529 }
530530
531- setForwardParameters (authenticationSession , uriBuilder );
532-
533531 if (getConfig ().isPkceEnabled ()) {
534532 String codeVerifier = PkceUtils .generateCodeVerifier ();
535533 String codeChallengeMethod = getConfig ().getPkceMethod ();
@@ -541,26 +539,35 @@ protected UriBuilder createAuthorizationUrl(AuthenticationRequest request) {
541539 uriBuilder .queryParam (OAuth2Constants .CODE_CHALLENGE_METHOD , codeChallengeMethod );
542540 }
543541
542+ appendForwardedParameters (authenticationSession , uriBuilder );
543+
544544 return uriBuilder ;
545545 }
546546
547- private void setForwardParameters (AuthenticationSessionModel authenticationSession , UriBuilder uriBuilder ) {
547+ private void appendForwardedParameters (AuthenticationSessionModel authenticationSession , UriBuilder uriBuilder ) {
548548 C config = getConfig ();
549549 String forwardParameterConfig = config .getForwardParameters () != null ? config .getForwardParameters (): OAuth2Constants .ACR_VALUES ;
550+ List <String > parameterNames = List .of (forwardParameterConfig .split ("\\ s*,\\ s*" ));
551+ StringBuilder query = new StringBuilder (uriBuilder .build ().getRawQuery ());
550552
551- for (String forwardParameter : List . of ( forwardParameterConfig . split ( " \\ s*, \\ s*" )) ) {
552- String name = AuthorizationEndpoint .LOGIN_SESSION_NOTE_ADDITIONAL_REQ_PARAMS_PREFIX + forwardParameter .trim ();
553- String parameter = authenticationSession .getClientNote (name );
553+ for (String name : parameterNames ) {
554+ String noteKey = AuthorizationEndpoint .LOGIN_SESSION_NOTE_ADDITIONAL_REQ_PARAMS_PREFIX + name .trim ();
555+ String value = authenticationSession .getClientNote (noteKey );
554556
555- if (parameter == null ) {
557+ if (value == null ) {
556558 // try a value set as a client note
557- parameter = authenticationSession .getClientNote (forwardParameter );
559+ value = authenticationSession .getClientNote (name );
558560 }
559561
560- if (parameter != null && !parameter .isEmpty ()) {
561- uriBuilder .queryParam (forwardParameter , URLEncoder .encode (parameter , StandardCharsets .UTF_8 ));
562+ if (value != null && !value .isEmpty ()) {
563+ if (!query .isEmpty ()) {
564+ query .append ("&" );
565+ }
566+ query .append (name ).append ("=" ).append (URLEncoder .encode (value , StandardCharsets .UTF_8 ));
562567 }
563568 }
569+
570+ uriBuilder .replaceQuery (query .toString ());
564571 }
565572
566573 /**
0 commit comments