6666use Utils \Services \IAuthService ;
6767use Utils \Services \ICheckPointService ;
6868use Utils \Services \ILogService ;
69+ use Utils \Services \IServerConfigurationService ;
6970
7071/**
7172 * Class OAuth2Protocol
@@ -844,9 +845,12 @@ static public function responseTypeBelongsToFlow(array $response_type, $flow = '
844845 */
845846 private $ memento_service ;
846847
848+ /**
849+ * @var IServerConfigurationService
850+ */
851+ private $ configuration_service ;
847852
848853 /**
849- * OAuth2Protocol constructor.
850854 * @param ILogService $log_service
851855 * @param IClientService $client_service
852856 * @param IClientRepository $client_repository
@@ -864,6 +868,7 @@ static public function responseTypeBelongsToFlow(array $response_type, $flow = '
864868 * @param IServerPrivateKeyRepository $server_private_key_repository
865869 * @param IClientJWKSetReader $jwk_set_reader_service
866870 * @param UserIPHelperProvider $ip_helper
871+ * @param IServerConfigurationService $configuration_service
867872 */
868873 public function __construct
869874 (
@@ -883,7 +888,8 @@ public function __construct
883888 IPrincipalService $ principal_service ,
884889 IServerPrivateKeyRepository $ server_private_key_repository ,
885890 IClientJWKSetReader $ jwk_set_reader_service ,
886- UserIPHelperProvider $ ip_helper
891+ UserIPHelperProvider $ ip_helper ,
892+ IServerConfigurationService $ configuration_service
887893 )
888894 {
889895
@@ -1005,6 +1011,8 @@ public function __construct
10051011 $ log_service ,
10061012 $ ip_helper
10071013 );
1014+
1015+ $ this ->configuration_service = $ configuration_service ;
10081016 }
10091017
10101018 /**
@@ -1464,7 +1472,7 @@ public function endSession(OAuth2Request $request = null)
14641472 if (!$ this ->last_request instanceof OAuth2LogoutRequest) throw new InvalidOAuth2Request ;
14651473
14661474 $ id_token_hint = $ this ->last_request ->getIdTokenHint ();
1467- $ client_id = null ;
1475+ $ client_id = $ this -> last_request -> getClientId () ;
14681476 $ user_id = null ;
14691477 $ user = null ;
14701478
@@ -1476,11 +1484,23 @@ public function endSession(OAuth2Request $request = null)
14761484 throw new InvalidOAuth2Request ('invalid id_token_hint! ' );
14771485 }
14781486
1479- $ client_id = $ jwt ->getClaimSet ()->getAudience ()->getString ();
1487+
1488+ $ jwt_client_id = $ jwt ->getClaimSet ()->getAudience ()->getString ()->getValue ();
1489+ $ jwt_issuer = $ jwt ->getClaimSet ()->getIssuer ()->getValue ();
1490+ $ current_issuer = $ this ->configuration_service ->getSiteUrl ();
1491+
1492+ if ($ jwt_issuer != $ current_issuer ){
1493+ throw new InvalidOAuth2Request (sprintf ("issuer provided on id_token_hint (%s) differs from current one %s " ,
1494+ $ jwt_issuer , $ current_issuer ));
1495+ }
14801496 $ user_id = $ jwt ->getClaimSet ()->getSubject ();
1481- }
1482- if (empty ($ client_id )) {
1483- $ client_id = $ this ->last_request ->getClientId ();
1497+
1498+ if (!empty ($ client_id ) && $ client_id != $ jwt_client_id ) {
1499+ throw new InvalidOAuth2Request (sprintf ("client id provided on id_token_hint (%s) differs from current one %s " ,
1500+ $ jwt_client_id , $ client_id ));
1501+ }
1502+
1503+ $ client_id = $ jwt_client_id ;
14841504 }
14851505
14861506 if (is_null ($ client_id )) {
0 commit comments