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
Add support for RFC7797 unencoded payloads #561
base: main
Are you sure you want to change the base?
Add support for RFC7797 unencoded payloads #561
Conversation
adds `encode_detached` to JWT, which produces a jwt with an empty payload segment adds support for the `b64` header, which when set to false will prevent the payload from being base64 encoded adds support for decoding JWTs with the `b64` header set to false adds support for decoding and verifying JWTs with detached payloads
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general LGTM, I made some minor comments.
@@ -22,7 +22,16 @@ def encode(payload, key, algorithm = 'HS256', header_fields = {}) | |||
Encode.new(payload: payload, | |||
key: key, | |||
algorithm: algorithm, | |||
headers: header_fields).segments | |||
headers: header_fields, | |||
detached: false).segments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can set detached as default false
@@ -15,11 +15,24 @@ def initialize(options) | |||
@algorithm = resolve_algorithm(options[:algorithm]) | |||
@headers = options[:headers].transform_keys(&:to_s) | |||
@headers[ALG_KEY] = @algorithm.alg | |||
@detached = options[:detached] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we can set as default false
@detached = options[:detached] || false
def parse_and_decode(segment, decode: true) | ||
if decode | ||
JWT::JSON.parse(::JWT::Base64.url_decode(segment)) | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can avoid else statement with a guard clause.
Hi guys, this feature is quite common, will be good to have this supported. |
This adds support for RFC7797 and addresses #309
Here is the specification: https://www.rfc-editor.org/rfc/rfc7797
Happy to receive feedback and would love to get this released soon as I need it for my current project.