Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added issuer validator #166

Merged
merged 1 commit into from Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
* Adding OAuth 2.0 Token Introspection #156
* Add optional parameters clientId/clientSecret for introspection #157 & #158
* Adding OAuth 2.0 Token Revocation #160
* Adding issuer validator #145

### Changed
* Bugfix/code cleanup #152
Expand Down
22 changes: 21 additions & 1 deletion src/OpenIDConnectClient.php
Expand Up @@ -204,6 +204,11 @@ class OpenIDConnectClient
*/
private $verifiedClaims = array();

/**
* @var callable validator function for issuer claim
*/
private $issuerValidator;

/**
* @var bool Allow OAuth 2 implicit flow; see http://openid.net/specs/openid-connect-core-1_0.html#ImplicitFlowAuth
*/
Expand Down Expand Up @@ -232,6 +237,10 @@ public function __construct($provider_url = null, $client_id = null, $client_sec

$this->clientID = $client_id;
$this->clientSecret = $client_secret;

$this->issuerValidator = function($iss){
return ($iss == $this->getIssuer() || $iss == $this->getWellKnownIssuer() || $iss == $this->getWellKnownIssuer(true));
};
}

/**
Expand Down Expand Up @@ -917,7 +926,7 @@ private function verifyJWTclaims($claims, $accessToken = null) {
$len = ((int)$bit)/16;
$expecte_at_hash = $this->urlEncode(substr(hash('sha'.$bit, $accessToken, true), 0, $len));
}
return (($claims->iss == $this->getIssuer() || $claims->iss == $this->getWellKnownIssuer() || $claims->iss == $this->getWellKnownIssuer(true))
return (($this->issuerValidator->__invoke($claims->iss))
&& (($claims->aud == $this->clientID) || in_array($this->clientID, $claims->aud))
&& ($claims->nonce == $this->getNonce())
&& ( !isset($claims->exp) || $claims->exp >= time() - $this->leeway)
Expand Down Expand Up @@ -1225,6 +1234,17 @@ public function getVerifyPeer()
return $this->verifyPeer;
}

/**
* Use this for custom issuer validation
* The given function should accept the issuer string from the JWT claim as the only argument
* and return true if the issuer is valid, otherwise return false
*
* @param callable $issuerValidator
*/
public function setIssuerValidator($issuerValidator){
$this->issuerValidator = $issuerValidator;
}

/**
* @param bool $allowImplicitFlow
*/
Expand Down