Skip to content

Commit

Permalink
Added support for the kid token header in the JWKsController
Browse files Browse the repository at this point in the history
  • Loading branch information
twellck authored May 14, 2024
1 parent 077ca66 commit a43edc2
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Laravel/JwksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ public function __invoke() {
// Source: https://www.tuxed.net/fkooman/blog/json_web_key_set.html
$keyInfo = openssl_pkey_get_details(openssl_pkey_get_public($publicKey));

$passportJWK = [
'alg' => 'RS256',
'kty' => 'RSA',
'use' => 'sig',
'n' => rtrim(str_replace(['+', '/'], ['-', '_'], base64_encode($keyInfo['rsa']['n'])), '='),
'e' => rtrim(str_replace(['+', '/'], ['-', '_'], base64_encode($keyInfo['rsa']['e'])), '='),
];

// Adds the kid if it is set in the config's token_headers
if ($kid = config('openid.token_headers.kid', false)) {
$passportJWK['kid'] = $kid;
}

$jsonData = [
'keys' => [
[
'alg' => 'RS256',
'kty' => 'RSA',
'use' => 'sig',
'n' => rtrim(str_replace(['+', '/'], ['-', '_'], base64_encode($keyInfo['rsa']['n'])), '='),
'e' => rtrim(str_replace(['+', '/'], ['-', '_'], base64_encode($keyInfo['rsa']['e'])), '='),
],
$passportJWK,
],
];

Expand Down

0 comments on commit a43edc2

Please sign in to comment.