Skip to content

Commit 9256f54

Browse files
committed
Fixed token hint on logout
Signed-off-by: smarcet@gmail.com <smarcet@gmail.com> Change-Id: I7d73960fc9acff7b274a120a031450c910978f36
1 parent d82000a commit 9256f54

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

app/libs/OAuth2/OAuth2Protocol.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
use Utils\Services\IAuthService;
6767
use Utils\Services\ICheckPointService;
6868
use 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

Comments
 (0)