Skip to content

Commit 8b14a70

Browse files
committed
OIDC Userinfo: Fixed issues with validation logic from changes
Also updated test to suit validation changes
1 parent 0958909 commit 8b14a70

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

app/Access/Oidc/OidcIdToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class OidcIdToken extends OidcJwtWithClaims implements ProvidesClaims
1111
*/
1212
public function validate(string $clientId): bool
1313
{
14-
parent::validateCommonClaims();
14+
parent::validateCommonTokenDetails($clientId);
1515
$this->validateTokenClaims($clientId);
1616

1717
return true;

app/Access/Oidc/OidcJwtWithClaims.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ protected function base64UrlDecode(string $encoded): string
5959
*
6060
* @throws OidcInvalidTokenException
6161
*/
62-
public function validateCommonTokenDetails(): bool
62+
public function validateCommonTokenDetails(string $clientId): bool
6363
{
6464
$this->validateTokenStructure();
6565
$this->validateTokenSignature();
66-
$this->validateCommonClaims();
66+
$this->validateCommonClaims($clientId);
6767

6868
return true;
6969
}
@@ -151,7 +151,7 @@ protected function validateTokenSignature(): void
151151
*
152152
* @throws OidcInvalidTokenException
153153
*/
154-
protected function validateCommonClaims(): void
154+
protected function validateCommonClaims(string $clientId): void
155155
{
156156
// 1. The Issuer Identifier for the OpenID Provider (which is typically obtained during Discovery)
157157
// MUST exactly match the value of the iss (issuer) Claim.
@@ -167,7 +167,7 @@ protected function validateCommonClaims(): void
167167
}
168168

169169
$aud = is_string($this->payload['aud']) ? [$this->payload['aud']] : $this->payload['aud'];
170-
if (!in_array($this->payload['aud'], $aud, true)) {
170+
if (!in_array($clientId, $aud, true)) {
171171
throw new OidcInvalidTokenException('Token audience value did not match the expected client_id');
172172
}
173173
}

app/Access/Oidc/OidcService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ protected function getUserDetailsFromToken(OidcIdToken $idToken, OidcAccessToken
253253
);
254254

255255
try {
256-
$response->validate($idToken->getClaim('sub'));
256+
$response->validate($idToken->getClaim('sub'), $settings->clientId);
257257
} catch (OidcInvalidTokenException $exception) {
258258
throw new OidcException("Userinfo endpoint response validation failed with error: {$exception->getMessage()}");
259259
}

app/Access/Oidc/OidcUserinfoResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public function __construct(ResponseInterface $response, string $issuer, array $
2525
/**
2626
* @throws OidcInvalidTokenException
2727
*/
28-
public function validate(string $idTokenSub): bool
28+
public function validate(string $idTokenSub, string $clientId): bool
2929
{
3030
if (!is_null($this->jwt)) {
31-
$this->jwt->validateCommonTokenDetails();
31+
$this->jwt->validateCommonTokenDetails($clientId);
3232
}
3333

3434
$sub = $this->getClaim('sub');

tests/Unit/OidcIdTokenTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function test_token_claim_error_cases()
113113
// 2. aud claim present
114114
['Missing token audience value', ['aud' => null]],
115115
// 2. aud claim validates all values against those expected (Only expect single)
116-
['Token audience value has 2 values, Expected 1', ['aud' => ['abc', 'def']]],
116+
['Token audience value has 2 values, Expected 1', ['aud' => ['xxyyzz.aaa.bbccdd.123', 'def']]],
117117
// 2. aud claim matches client id
118118
['Token audience value did not match the expected client_id', ['aud' => 'xxyyzz.aaa.bbccdd.456']],
119119
// 4. azp claim matches client id if present

0 commit comments

Comments
 (0)