@@ -100,6 +100,15 @@ class OpenID_Connect_Generic_Client {
100100 */
101101 private $ endpoint_jwks ;
102102
103+ /**
104+ * The issuer URL for JWT validation.
105+ *
106+ * @see OpenID_Connect_Generic_Option_Settings::issuer
107+ *
108+ * @var string
109+ */
110+ private $ issuer ;
111+
103112 /**
104113 * The JWKS cache TTL in seconds.
105114 *
@@ -146,12 +155,13 @@ class OpenID_Connect_Generic_Client {
146155 * @param string $redirect_uri @see OpenID_Connect_Generic_Option_Settings::redirect_uri for description.
147156 * @param string $acr_values @see OpenID_Connect_Generic_Option_Settings::acr_values for description.
148157 * @param string $endpoint_jwks @see OpenID_Connect_Generic_Option_Settings::endpoint_jwks for description.
158+ * @param string $issuer @see OpenID_Connect_Generic_Option_Settings::issuer for description.
149159 * @param int $jwks_cache_ttl @see OpenID_Connect_Generic_Option_Settings::jwks_cache_ttl for description.
150160 * @param int $state_time_limit @see OpenID_Connect_Generic_Option_Settings::state_time_limit for description.
151161 * @param bool $allow_internal_idp @see OpenID_Connect_Generic_Option_Settings::allow_internal_idp for description.
152162 * @param OpenID_Connect_Generic_Option_Logger $logger The plugin logging object instance.
153163 */
154- public function __construct ( $ client_id , $ client_secret , $ scope , $ endpoint_login , $ endpoint_userinfo , $ endpoint_token , $ redirect_uri , $ acr_values , $ endpoint_jwks , $ jwks_cache_ttl , $ state_time_limit , $ allow_internal_idp , $ logger ) {
164+ public function __construct ( $ client_id , $ client_secret , $ scope , $ endpoint_login , $ endpoint_userinfo , $ endpoint_token , $ redirect_uri , $ acr_values , $ endpoint_jwks , $ issuer , $ jwks_cache_ttl , $ state_time_limit , $ allow_internal_idp , $ logger ) {
155165 $ this ->client_id = $ client_id ;
156166 $ this ->client_secret = $ client_secret ;
157167 $ this ->scope = $ scope ;
@@ -161,6 +171,7 @@ public function __construct( $client_id, $client_secret, $scope, $endpoint_login
161171 $ this ->redirect_uri = $ redirect_uri ;
162172 $ this ->acr_values = $ acr_values ;
163173 $ this ->endpoint_jwks = $ endpoint_jwks ;
174+ $ this ->issuer = $ issuer ;
164175 $ this ->jwks_cache_ttl = $ jwks_cache_ttl ;
165176 $ this ->state_time_limit = $ state_time_limit ;
166177 $ this ->allow_internal_idp = $ allow_internal_idp ;
@@ -543,11 +554,16 @@ public function get_id_token_claim( $token_response ) {
543554
544555 // Check if JWKS endpoint is configured for JWT signature verification.
545556 if ( ! empty ( $ this ->endpoint_jwks ) ) {
557+ // Use configured issuer if provided, otherwise derive from endpoint_login.
558+ $ issuer = ! empty ( $ this ->issuer )
559+ ? $ this ->issuer
560+ : $ this ->get_issuer_from_endpoint ( $ this ->endpoint_login );
561+
546562 // Use JWT validator for secure signature verification.
547563 $ jwt_validator = new OpenID_Connect_Generic_JWT_Validator (
548564 $ this ->endpoint_jwks ,
549565 $ this ->client_id ,
550- $ this -> get_issuer_from_endpoint ( $ this -> endpoint_login ) ,
566+ $ issuer ,
551567 $ this ->jwks_cache_ttl ,
552568 $ this ->allow_internal_idp ,
553569 $ this ->logger
@@ -671,15 +687,16 @@ public function validate_id_token_claim( $id_token_claim ) {
671687 return new WP_Error ( 'invalid-aud ' , __ ( 'Token audience does not match client. ' , 'daggerhart-openid-connect-generic ' ), $ id_token_claim );
672688 }
673689
674- // Validate issuer claim if endpoint_login is configured.
675- if ( ! empty ( $ this ->endpoint_login ) ) {
690+ // Validate issuer claim if configured or endpoint_login is available.
691+ $ expected_issuer = ! empty ( $ this ->issuer ) ?
692+ $ this ->issuer :
693+ ( ! empty ( $ this ->endpoint_login ) ? $ this ->get_issuer_from_endpoint ( $ this ->endpoint_login ) : '' );
694+
695+ if ( ! empty ( $ expected_issuer ) ) {
676696 if ( ! isset ( $ id_token_claim ['iss ' ] ) ) {
677697 return new WP_Error ( 'missing-iss ' , __ ( 'Token missing issuer claim. ' , 'daggerhart-openid-connect-generic ' ), $ id_token_claim );
678698 }
679699
680- // Extract expected issuer from endpoint_login (base URL).
681- $ expected_issuer = $ this ->get_issuer_from_endpoint ( $ this ->endpoint_login );
682-
683700 if ( rtrim ( $ id_token_claim ['iss ' ], '/ ' ) !== rtrim ( $ expected_issuer , '/ ' ) ) {
684701 return new WP_Error (
685702 'invalid-iss ' ,
0 commit comments