Skip to content

Commit

Permalink
Merge pull request #322 from ricklambrechts/add-support-for-private-k…
Browse files Browse the repository at this point in the history
…ey-jwt

Added support for private_key_jwt authentication method
  • Loading branch information
DeepDiver1975 authored Sep 28, 2022
2 parents 7672086 + bddb3bf commit fba1440
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]
* Added support for `private_key_jwt` Client Authentication method #322

## Fixed

Expand Down
31 changes: 31 additions & 0 deletions src/OpenIDConnectClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ class OpenIDConnectClient
*/
private $issuerValidator;

/**
* @var callable|null generator function for private key jwt client authentication
*/
private $privateKeyJwtGenerator;

/**
* @var bool Allow OAuth 2 implicit flow; see http://openid.net/specs/openid-connect-core-1_0.html#ImplicitFlowAuth
*/
Expand Down Expand Up @@ -798,6 +803,12 @@ protected function requestTokens($code, $headers = array()) {
unset($token_params['client_id']);
}

// When there is a private key jwt generator and it is supported then use it as client authentication
if ($this->privateKeyJwtGenerator !== null && in_array('private_key_jwt', $token_endpoint_auth_methods_supported, true)) {
$token_params['client_assertion_type'] = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer';
$token_params['client_assertion'] = $this->privateKeyJwtGenerator->__invoke($token_endpoint);
}

$ccm = $this->getCodeChallengeMethod();
$cv = $this->getCodeVerifier();
if (!empty($ccm) && !empty($cv)) {
Expand Down Expand Up @@ -1454,6 +1465,18 @@ public function setIssuerValidator($issuerValidator) {
$this->issuerValidator = $issuerValidator;
}

/**
* Use this for private_key_jwt client authentication
* The given function should accept the token_endpoint string as the only argument
* and return a jwt signed with your private key according to:
* https://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication
*
* @param callable $privateKeyJwtGenerator
*/
public function setPrivateKeyJwtGenerator($privateKeyJwtGenerator) {
$this->privateKeyJwtGenerator = $privateKeyJwtGenerator;
}

/**
* @param bool $allowImplicitFlow
*/
Expand Down Expand Up @@ -1923,6 +1946,14 @@ public function getIssuerValidator() {
return $this->issuerValidator;
}


/**
* @return callable
*/
public function getPrivateKeyJwtGenerator() {
return $this->privateKeyJwtGenerator;
}

/**
* @return int
*/
Expand Down

0 comments on commit fba1440

Please sign in to comment.