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

Add support for RFC7797 unencoded payloads #561

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

Conversation

WriterZephos
Copy link

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.

Bryant Morrill added 3 commits May 4, 2023 18:03
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
Copy link

@abiagini abiagini left a 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

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]

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

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.

@abiagini
Copy link

Hi guys, this feature is quite common, will be good to have this supported.

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.

None yet

2 participants