Skip to content

Commit c456cda

Browse files
committed
Check state earlier
1 parent 499dad9 commit c456cda

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/OpenIDConnectClient.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,16 @@ public function authenticate(): bool
385385
if (isset($_REQUEST['code'])) {
386386

387387
$code = $_REQUEST['code'];
388+
389+
// Do an OpenID Connect session check
390+
if (!isset($_REQUEST['state']) || ($_REQUEST['state'] !== $this->getState())) {
391+
throw new OpenIDConnectClientException('Unable to determine state');
392+
}
393+
394+
// Cleanup state
395+
$this->unsetState();
396+
397+
// Request token from the server using the code
388398
$token_json = $this->requestTokens($code);
389399

390400
// Throw an error if the server returns one
@@ -395,14 +405,6 @@ public function authenticate(): bool
395405
throw new OpenIDConnectClientException('Got response: ' . $token_json->error);
396406
}
397407

398-
// Do an OpenID Connect session check
399-
if (!isset($_REQUEST['state']) || ($_REQUEST['state'] !== $this->getState())) {
400-
throw new OpenIDConnectClientException('Unable to determine state');
401-
}
402-
403-
// Cleanup state
404-
$this->unsetState();
405-
406408
if (!property_exists($token_json, 'id_token')) {
407409
throw new OpenIDConnectClientException('User did not authorize openid scope.');
408410
}

0 commit comments

Comments
 (0)