-
-
Notifications
You must be signed in to change notification settings - Fork 621
feat: Add Key ID (kid) support to JWT assertions #652
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
Conversation
Adds support for the 'kid' (Key ID) header parameter in JWT assertions, allowing clients to specify the key identifier used for signing. This improves key management and verification in systems consuming JWTs. Updates `OAuth2::Strategy::Assertion#build_assertion` to accept `kid` in `encoding_opts` and include it in the JWT header. Also adds a test case to verify the functionality.
Removes an unnecessary empty line within the `build_assertion` method for improved code style and consistency.
Updates `.rubocop_gradual.lock` due to changes in `spec/oauth2/strategy/assertion_spec.rb`. This reflects the introduction of the new `kid` test context.
@pboling would love to have your review on this. Thank you. 🙏🏽 |
Pull Request Test Coverage Report for Build 15272497358Details
💛 - Coveralls |
Kids are great! 😊 |
I will release this in 2.0.12 soon |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #652 +/- ##
===========================
===========================
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CodeCov has inexplicably stopped working. This repo still has 100% coverage, and uses coveralls as an alternative service. |
Feature: Support Key ID (kid) in JWT Bearer Assertions (RFC 7515)
This pull request implements support for the
kid
(Key ID) header parameter in JWT bearer assertions, as defined in RFC 7515 (JSON Web Signature - JWS).The
OAuth2::Strategy::Assertion
class currently constructs JWTs for client authentication and authorization grants. While it supports specifying thealg
(algorithm), it lacks the mechanism to pass akid
. Thekid
parameter is highly recommended in scenarios where a signer has multiple keys or undergoes regular key rotation, as it allows the JWT recipient to efficiently locate the appropriate public key for signature validation.Motivation
To facilitate more robust and scalable OAuth2 client implementations, especially for integrations with providers that leverage
kid
for key discovery and management, this feature becomes essential. It aligns the library's JWT generation capabilities more closely with common production practices and the broader JWT ecosystem.Implementation Details
private
methodbuild_assertion
withinOAuth2::Strategy::Assertion
has been modified.:kid
key within theencoding_opts
hash passed toget_token
.:kid
is provided, it is correctly added as a header parameter to the JWT usingJWT.encode(..., headers)
.kid
is correctly embedded in the JWT header when supplied.