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 support for the 'kid' token header in the JWKsController #16

Merged
merged 2 commits into from
May 14, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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
Loading