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

Ability to extend JWT encoding and decoding behaviour #460

Closed
wants to merge 33 commits into from

Conversation

anakinj
Copy link
Member

@anakinj anakinj commented Dec 27, 2021

This is a second attempt of making it possible to extend the token decoding/encoding behaviour. First version of the same idea in #434

For example to support deflating the payload after verification as discussed in #428

Rough example on how it works

class MyJWTHandler
  include ::JWT

  algorithm 'ES256'

  jwk_resolver do |_options|
    # Load JWKs from trusted source
  end

  signing_key es256_private_key

  encode_payload do |payload|
    ::Base64.urlsafe_encode64(::JWT::JSON.generate(payload)), padding: true)
  end

  decode_payload do |raw_payload|
    ::JWT::JSON.parse(::Base64.urlsafe_decode64(raw_payload))
  end
end

Focus now was on the decoding/encoding and signing of the token. The mechanics could be extended to claims etc..

lib/jwt/extension.rb Outdated Show resolved Hide resolved
lib/jwt/encode.rb Outdated Show resolved Hide resolved
lib/jwt/encode.rb Outdated Show resolved Hide resolved
lib/jwt/decode.rb Outdated Show resolved Hide resolved
excpt
excpt previously approved these changes Dec 27, 2021
@anakinj
Copy link
Member Author

anakinj commented Dec 30, 2021

Im going to refine this a little bit more. Not super happy with the methods setting the signing keys with.

@anakinj anakinj marked this pull request as draft January 7, 2022 06:28
lib/jwt/extension/keys.rb Outdated Show resolved Hide resolved
lib/jwt/encode.rb Outdated Show resolved Hide resolved
lib/jwt/decode_token.rb Outdated Show resolved Hide resolved
lib/jwt/decode_token.rb Outdated Show resolved Hide resolved
lib/jwt/decode_token.rb Outdated Show resolved Hide resolved
lib/jwt/decode_token.rb Outdated Show resolved Hide resolved
@anakinj
Copy link
Member Author

anakinj commented Sep 11, 2022

Im going to close this one and yet again try to tackle issues one by one.

First up is this #510

@anakinj anakinj closed this Sep 11, 2022
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