Skip to content

Commit fba1440

Browse files
Merge pull request #322 from ricklambrechts/add-support-for-private-key-jwt
Added support for private_key_jwt authentication method
2 parents 7672086 + bddb3bf commit fba1440

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [unreleased]
8+
* Added support for `private_key_jwt` Client Authentication method #322
89

910
## Fixed
1011

src/OpenIDConnectClient.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ class OpenIDConnectClient
215215
*/
216216
private $issuerValidator;
217217

218+
/**
219+
* @var callable|null generator function for private key jwt client authentication
220+
*/
221+
private $privateKeyJwtGenerator;
222+
218223
/**
219224
* @var bool Allow OAuth 2 implicit flow; see http://openid.net/specs/openid-connect-core-1_0.html#ImplicitFlowAuth
220225
*/
@@ -798,6 +803,12 @@ protected function requestTokens($code, $headers = array()) {
798803
unset($token_params['client_id']);
799804
}
800805

806+
// When there is a private key jwt generator and it is supported then use it as client authentication
807+
if ($this->privateKeyJwtGenerator !== null && in_array('private_key_jwt', $token_endpoint_auth_methods_supported, true)) {
808+
$token_params['client_assertion_type'] = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer';
809+
$token_params['client_assertion'] = $this->privateKeyJwtGenerator->__invoke($token_endpoint);
810+
}
811+
801812
$ccm = $this->getCodeChallengeMethod();
802813
$cv = $this->getCodeVerifier();
803814
if (!empty($ccm) && !empty($cv)) {
@@ -1454,6 +1465,18 @@ public function setIssuerValidator($issuerValidator) {
14541465
$this->issuerValidator = $issuerValidator;
14551466
}
14561467

1468+
/**
1469+
* Use this for private_key_jwt client authentication
1470+
* The given function should accept the token_endpoint string as the only argument
1471+
* and return a jwt signed with your private key according to:
1472+
* https://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication
1473+
*
1474+
* @param callable $privateKeyJwtGenerator
1475+
*/
1476+
public function setPrivateKeyJwtGenerator($privateKeyJwtGenerator) {
1477+
$this->privateKeyJwtGenerator = $privateKeyJwtGenerator;
1478+
}
1479+
14571480
/**
14581481
* @param bool $allowImplicitFlow
14591482
*/
@@ -1923,6 +1946,14 @@ public function getIssuerValidator() {
19231946
return $this->issuerValidator;
19241947
}
19251948

1949+
1950+
/**
1951+
* @return callable
1952+
*/
1953+
public function getPrivateKeyJwtGenerator() {
1954+
return $this->privateKeyJwtGenerator;
1955+
}
1956+
19261957
/**
19271958
* @return int
19281959
*/

0 commit comments

Comments
 (0)