Draft
Conversation
anarchivist
requested changes
Apr 13, 2026
Member
anarchivist
left a comment
There was a problem hiding this comment.
I think this needs some refactoring - we should look at using ruby-jwt's native methods here rather than rolling our own.
Comment on lines
+20
to
+47
| def decode_and_verify_jwt(token) | ||
| # Decode header to get the 'kid' | ||
| header = JWT.decode(token, nil, false).last | ||
| kid = header['kid'] | ||
|
|
||
| # Find the key from the JWK set | ||
| jwk = jwk_set.keys.find { |key| key.kid == kid } | ||
| raise JWT::VerificationError, 'Key not found in JWKS' unless jwk | ||
|
|
||
| public_key = jwk.public_key | ||
|
|
||
| options = { | ||
| algorithm: 'RS256', | ||
| verify_expiration: true, | ||
| verify_aud: false, | ||
| verify_iss: true, | ||
| iss: EXPECTED_ISS | ||
| } | ||
|
|
||
| # Returns [payload, header] array if valid | ||
| JWT.decode(token, public_key, true, options) | ||
| rescue JWT::ExpiredSignature | ||
| raise JWT::VerificationError, 'Token has expired' | ||
| rescue JWT::InvalidIssuerError | ||
| raise JWT::VerificationError, 'Token issuer mismatch' | ||
| rescue JWT::DecodeError => e | ||
| raise JWT::VerificationError, "Invalid JWT: #{e.message}" | ||
| end |
Member
There was a problem hiding this comment.
Would it be possible for us to use JWT:JWK::Keyfinder to validate the signature? I think that will greatly simplify the code here.
Member
There was a problem hiding this comment.
Similarly, there's a lot in this file that seems to duplicate what's in JWT::JWK's methods here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.