Skip to content

Commit ab23794

Browse files
committed
make verifyJWTclaims easier to debug
1 parent 743f68d commit ab23794

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

src/OpenIDConnectClient.php

+33-9
Original file line numberDiff line numberDiff line change
@@ -717,15 +717,39 @@ private function verifyJWTclaims($claims, $accessToken = null)
717717
$bit = '256';
718718
}
719719
$len = ((int)$bit)/16;
720-
$expecte_at_hash = $this->urlEncode(substr(hash('sha'.$bit, $accessToken, true), 0, $len));
720+
$expected_at_hash = $this->urlEncode(substr(hash('sha'.$bit, $accessToken, true), 0, $len));
721721
}
722-
return (($claims->iss == $this->getProviderURL())
723-
&& (($claims->aud == $this->clientID) || (in_array($this->clientID, $claims->aud)))
724-
&& ($claims->nonce == $this->getNonce())
725-
&& (!isset($claims->exp) || $claims->exp >= time())
726-
&& (!isset($claims->nbf) || $claims->nbf <= time())
727-
&& (!isset($claims->at_hash) || $claims->at_hash == $expecte_at_hash)
728-
);
722+
723+
if ($claims->iss !== $this->getProviderURL()) {
724+
throw new Exception('iss does not match getProviderURL:'.$claims->iss.' !== '.$this->getProviderURL());
725+
}
726+
727+
if ($claims->aud !== $this->clientID) {
728+
if (!in_array($this->clientID, $claims->aud)) {
729+
throw new Exception('aud does not match clientID:'.json_encode($claims->aud).' <> '.$this->clientID);
730+
}
731+
}
732+
733+
if ($claims->nonce !== $this->getNonce()) {
734+
throw new Exception('nonce does not match getNonce:'.$claims->nonce.' !== '.$this->getNonce());
735+
}
736+
if (isset($claims->exp)) {
737+
if ($claims->exp <= time()) {
738+
throw new Exception('exp already:'.$claims->exp .' <= '.time());
739+
}
740+
}
741+
if (isset($claims->nbf)) {
742+
if ($claims->nbf >= time()) {
743+
throw new Exception('nbf not yet:'.$claims->nbf .' >= '.time());
744+
}
745+
}
746+
if (isset($claims->at_hash)) {
747+
if ($claims->at_hash !== $expected_at_hash) {
748+
throw new Exception('at_hash does not match expected_at_hash:'.$claims->at_hash.' !== '.$expected_at_hash);
749+
}
750+
}
751+
752+
return true;
729753
}
730754

731755
/**
@@ -1173,7 +1197,7 @@ protected function setNonce($nonce)
11731197
*/
11741198
protected function getNonce()
11751199
{
1176-
static::getSession('openid_connect_nonce');
1200+
return static::getSession('openid_connect_nonce');
11771201
}
11781202

11791203
/**

0 commit comments

Comments
 (0)