From a43edc28d7ebdfc350317811efbd6d9081472d02 Mon Sep 17 00:00:00 2001 From: Tim Wellbrock <25177907+twellck@users.noreply.github.com> Date: Tue, 14 May 2024 18:38:01 +1000 Subject: [PATCH 1/2] Added support for the kid token header in the JWKsController --- src/Laravel/JwksController.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Laravel/JwksController.php b/src/Laravel/JwksController.php index 7fcd444..2f980e9 100644 --- a/src/Laravel/JwksController.php +++ b/src/Laravel/JwksController.php @@ -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, ], ]; From 8a3856671c043dc6357d5882f55712446f276927 Mon Sep 17 00:00:00 2001 From: Tim Wellbrock <25177907+twellck@users.noreply.github.com> Date: Tue, 14 May 2024 18:44:36 +1000 Subject: [PATCH 2/2] Updated Documentation to reflect JWKsController changes --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2c1cb41..6515448 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,8 @@ Example: Additionally, you can configure the JWKS url and some settings for discovery in the config file. +_Note: If you define a `kid` header, it will be added to the JWK returned at the jwks_url (if `jwks` is enabled in the configuration)._ + ## Support You can fill an issue in the github section dedicated for that. I'll try to maintain this fork.