Skip to content

Support verifying token signature using a JWK #692

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

anakinj
Copy link
Member

@anakinj anakinj commented Jun 21, 2025

Description

This tries to implement the idea in #400 by using the alg/crv parameter to resolve the algorithm and use that for verifying the signature.

Checklist

Before the PR can be merged be sure the following are checked:

  • There are tests for the fix or feature added/changed
  • A description of the changes and a reference to the PR has been added to CHANGELOG.md. More details in the CONTRIBUTING.md

@anakinj anakinj changed the title Verification via JWK suppport Figure out algorithm from the alg JWK parameter Jun 21, 2025
@anakinj anakinj force-pushed the verification-via-jwk-suppport branch from 933099f to 2bbf6bc Compare June 21, 2025 19:11
@anakinj anakinj changed the title Figure out algorithm from the alg JWK parameter Support verifying token signature using a JWK Jun 21, 2025
@anakinj anakinj requested a review from Copilot June 21, 2025 20:10
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables token signature verification using a JWK by deriving the correct JWA algorithm from the JWK’s alg or crv parameters.

  • Adds verify/sign methods and resolve_algorithm logic in JWK key classes
  • Refactors EncodedToken#verify_signature! and valid_signature? to use JWKs and key finders
  • Adds corresponding tests, updates examples in README.md, and updates CHANGELOG.md

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
spec/jwt/jwk/rsa_spec.rb Adds RSA JWK verification tests
spec/jwt/jwk/ec_spec.rb Adds EC JWK verification tests
spec/jwt/encoded_token_spec.rb Tests EncodedToken#verify_signature! with a JWK key
spec/integration/readme_examples_spec.rb Adds readme integration example for JWK verification
lib/jwt/jwk/key_base.rb Implements verify/sign and resolve_algorithm
lib/jwt/jwk/ec.rb Overrides resolve_algorithm to handle crv
lib/jwt/jwa/ecdsa.rb Exposes curve_by_name helper
lib/jwt/jwa.rb Introduces VerificationContext and verifier factory
lib/jwt/encoded_token.rb Refactors signature validation to support JWKs
README.md Adds example for JWK-based verification
CHANGELOG.md Documents new JWK verification feature
Comments suppressed due to low confidence (3)

spec/jwt/jwk/rsa_spec.rb:120

  • The context description is duplicated. Rename this to something like 'when the jwk has an invalid alg value'.
    context 'when the jwk is missing the alg header' do

spec/jwt/jwk/ec_spec.rb:137

  • The description says 'returns true' but the expectation checks for false. Update the example description to 'returns false'.
        it 'returns true' do

spec/integration/readme_examples_spec.rb:477

  • This example invokes verify! without any assertion. Consider adding an expect { ... }.not_to raise_error or other matcher to ensure the behavior is verified.
      encoded_token.verify!(signature: { key: jwk })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant