Skip to content

Commit bd202c3

Browse files
committed
fix: Fix $jwt not defined and nonce validation in Implicit Flow
1 parent aa6dce6 commit bd202c3

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/Traits/ImplictFlow.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ private function implictFlow(Request $request, string $id_token): bool
3333
}
3434
Session::remove('oidc_state');
3535

36-
$this->validateJWT($id_token);
36+
$jwt = $this->jwt()->parser()->parse($id_token);
37+
$this->validateJWT($jwt);
3738

38-
// Save the id token
39-
$this->id_token = $id_token;
40-
41-
if ($this->enable_nonce && $request->get('nonce') === Session::get('oidc_nonce')) {
42-
return true;
39+
if ($this->enable_nonce && Session::get('oidc_nonce') !== $jwt->claims()->get('nonce')) {
40+
throw new ClientException("Generated nonce is not equal to the one returned by the server.");
4341
}
4442
Session::remove('oidc_nonce');
4543

46-
throw new ClientException('Unable to verify JWT claims');
44+
// Save the id token
45+
$this->id_token = $id_token;
46+
47+
return true;
4748
}
4849
}

src/Traits/JWT.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ trait JWT
4646
private bool $jwt_plain_key;
4747
private int $leeway;
4848

49-
private function validateJWT(string $id_token): void
49+
private function validateJWT(string|\Lcobucci\JWT\Token $jwt): void
5050
{
5151
try {
52-
$jwt = $this->jwt()->parser()->parse($id_token);
52+
if (is_string($jwt)) {
53+
$jwt = $this->jwt()->parser()->parse($jwt);
54+
}
5355
$claims = $jwt->claims();
5456
if (!(
5557
$claims->has(RegisteredClaims::EXPIRATION_TIME)

src/Traits/Token.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ private function token(Request $request, string $code): bool
140140
throw new ClientException('User did not authorize openid scope.');
141141
}
142142

143-
$this->validateJWT($token_response->get('id_token'));
143+
$jwt = $this->jwt()->parser()->parse($token_response->get('id_token'));
144+
$this->validateJWT($jwt);
144145

145146
if ($this->enable_nonce && Session::get('oidc_nonce') !== $jwt->claims()->get('nonce')) {
146147
throw new ClientException("Generated nonce is not equal to the one returned by the server.");

0 commit comments

Comments
 (0)