Skip to content

Commit

Permalink
Validate state before ID Token request
Browse files Browse the repository at this point in the history
  • Loading branch information
ricklambrechts committed Sep 30, 2024
1 parent f7c91b9 commit 7ef4516
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/OpenIDConnectClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,15 @@ public function authenticate(): bool

// If we have an authorization code then proceed to request a token
if (isset($_REQUEST['code'])) {
// Do an OpenID Connect session check
if (!isset($_REQUEST['state']) || ($_REQUEST['state'] !== $this->getState())) {
throw new OpenIDConnectClientException('Unable to determine state');
}

// Cleanup state
$this->unsetState();

// Request ID Token
$code = $_REQUEST['code'];
$token_json = $this->requestTokens($code);

Expand All @@ -318,14 +326,6 @@ public function authenticate(): bool
throw new OpenIDConnectClientException('Got response: ' . $token_json->error);
}

// Do an OpenID Connect session check
if (!isset($_REQUEST['state']) || ($_REQUEST['state'] !== $this->getState())) {
throw new OpenIDConnectClientException('Unable to determine state');
}

// Cleanup state
$this->unsetState();

if (!property_exists($token_json, 'id_token')) {
throw new OpenIDConnectClientException('User did not authorize openid scope.');
}
Expand Down Expand Up @@ -379,7 +379,7 @@ public function authenticate(): bool
$accessToken = $_REQUEST['access_token'] ?? null;

// Do an OpenID Connect session check
if (!isset($_REQUEST['state']) || ($_REQUEST['state'] !== $this->getState())) {
if (!isset($_REQUEST['state']) || ($_REQUEST['state'] !== $this->getState())) {
throw new OpenIDConnectClientException('Unable to determine state');
}

Expand Down

0 comments on commit 7ef4516

Please sign in to comment.