forked from jumbojett/OpenID-Connect-PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* upstream/master: fix: protected responseContentType to allow overloading of fetchUrl function (jumbojett#446) test: unit tests for verifyJWTClaims and different aud claims (jumbojett#443) Fix TypeError in `verifyJWTClaims` (jumbojett#442) release: v1.0.2 (jumbojett#439) test: add unit test for SERVER_PORT type cast (jumbojett#438) fix: bring back jumbojett#404 (jumbojett#437) release: v1.0.1 (jumbojett#432) fix: protected $responseCode to allow proper overloading of fetchURL() (jumbojett#433) chore(deps-dev): update yoast/phpunit-polyfills requirement from ^1.0 to ^2.0 (jumbojett#430) chore(deps): update phpseclib/phpseclib requirement from ~3.0 to ^3.0.7 ci: run GitHub workflows on pull requests and pushes to master (jumbojett#431) chore: enable dependabot for composer (jumbojett#429) fix: handle JWT decode of non JWT tokens (jumbojett#428) fix: method signatures after 1.0 release (jumbojett#427)
- Loading branch information
Showing
6 changed files
with
151 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* | ||
* Copyright MITRE 2020 | ||
* | ||
* OpenIDConnectClient for PHP5 | ||
* OpenIDConnectClient for PHP7+ | ||
* Author: Michael Jett <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
|
@@ -25,7 +25,6 @@ | |
|
||
use Error; | ||
use Exception; | ||
use phpseclib3\Crypt\PublicKeyLoader; | ||
use phpseclib3\Crypt\RSA; | ||
use phpseclib3\Math\BigInteger; | ||
use stdClass; | ||
|
@@ -145,12 +144,12 @@ class OpenIDConnectClient | |
/** | ||
* @var int|null Response code from the server | ||
*/ | ||
private $responseCode; | ||
protected $responseCode; | ||
|
||
/** | ||
* @var string|null Content type from the server | ||
*/ | ||
private $responseContentType; | ||
protected $responseContentType; | ||
|
||
/** | ||
* @var array holds response types | ||
|
@@ -380,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'); | ||
} | ||
|
||
|
@@ -691,6 +690,7 @@ public function getRedirectURL(): string | |
if (isset($_SERVER['HTTP_X_FORWARDED_PORT'])) { | ||
$port = (int)$_SERVER['HTTP_X_FORWARDED_PORT']; | ||
} elseif (isset($_SERVER['SERVER_PORT'])) { | ||
# keep this case - even if some tool claim it is unnecessary | ||
$port = (int)$_SERVER['SERVER_PORT']; | ||
} elseif ($protocol === 'https') { | ||
$port = 443; | ||
|
@@ -1212,8 +1212,10 @@ protected function verifyJWTClaims($claims, string $accessToken = null): bool | |
$len = ((int)$bit)/16; | ||
$expected_at_hash = $this->urlEncode(substr(hash('sha'.$bit, $accessToken, true), 0, $len)); | ||
} | ||
$auds = $claims->aud; | ||
$auds = is_array( $auds ) ? $auds : [ $auds ]; | ||
return (($this->validateIssuer($claims->iss)) | ||
&& (($claims->aud === $this->clientID) || in_array($this->clientID, $claims->aud, true)) | ||
&& (in_array($this->clientID, $auds, true)) | ||
&& ($claims->sub === $this->getIdTokenPayload()->sub) | ||
&& (!isset($claims->nonce) || $claims->nonce === $this->getNonce()) | ||
&& ( !isset($claims->exp) || ((is_int($claims->exp)) && ($claims->exp >= time() - $this->leeway))) | ||
|
@@ -1232,12 +1234,11 @@ protected function urlEncode(string $str): string | |
/** | ||
* @param string $jwt encoded JWT | ||
* @param int $section the section we would like to decode | ||
* @return object | ||
* @return object|string|null | ||
*/ | ||
protected function decodeJWT(string $jwt, int $section = 0): stdClass { | ||
|
||
protected function decodeJWT(string $jwt, int $section = 0) { | ||
$parts = explode('.', $jwt); | ||
return json_decode(base64url_decode($parts[$section]), false); | ||
return json_decode(base64url_decode($parts[$section] ?? ''), false); | ||
} | ||
|
||
/** | ||
|
@@ -1699,7 +1700,10 @@ public function revokeToken(string $token, string $token_type_hint = '', string | |
return json_decode($this->fetchURL($revocation_endpoint, $post_params, $headers), false); | ||
} | ||
|
||
public function getClientName(): string | ||
/** | ||
* @return string|null | ||
*/ | ||
public function getClientName() | ||
{ | ||
return $this->clientName; | ||
} | ||
|
@@ -1709,14 +1713,14 @@ public function setClientName(string $clientName) { | |
} | ||
|
||
/** | ||
* @return string | ||
* @return string|null | ||
*/ | ||
public function getClientID() { | ||
return $this->clientID; | ||
} | ||
|
||
/** | ||
* @return string | ||
* @return string|null | ||
*/ | ||
public function getClientSecret() { | ||
return $this->clientSecret; | ||
|
@@ -1731,17 +1735,30 @@ public function setAccessToken(string $accessToken) { | |
$this->accessToken = $accessToken; | ||
} | ||
|
||
public function getAccessToken(): string | ||
/** | ||
* @return string|null | ||
*/ | ||
public function getAccessToken() | ||
{ | ||
return $this->accessToken; | ||
} | ||
|
||
public function getRefreshToken(): string | ||
/** | ||
* @return string|null | ||
*/ | ||
public function getRefreshToken() | ||
{ | ||
return $this->refreshToken; | ||
} | ||
|
||
public function getIdToken(): string | ||
public function setIdToken(string $idToken) { | ||
$this->idToken = $idToken; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getIdToken() | ||
{ | ||
return $this->idToken; | ||
} | ||
|
@@ -1754,21 +1771,21 @@ public function getAccessTokenHeader() { | |
} | ||
|
||
/** | ||
* @return object | ||
* @return object|string|null | ||
*/ | ||
public function getAccessTokenPayload() { | ||
return $this->decodeJWT($this->accessToken, 1); | ||
} | ||
|
||
/** | ||
* @return object | ||
* @return object|string|null | ||
*/ | ||
public function getIdTokenHeader() { | ||
return $this->decodeJWT($this->idToken); | ||
} | ||
|
||
/** | ||
* @return object | ||
* @return object|string|null | ||
*/ | ||
public function getIdTokenPayload() { | ||
return $this->decodeJWT($this->idToken, 1); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters