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

Proposal of simple JWK support #289

Merged
merged 1 commit into from Jan 17, 2019
Merged

Proposal of simple JWK support #289

merged 1 commit into from Jan 17, 2019

Conversation

anakinj
Copy link
Member

@anakinj anakinj commented Dec 1, 2018

This PR is related to issue #158

Been using this gem for handling JWT tokens but with the lack of JWK support been forced to also include another JWT gem in the picture (https://rubygems.org/gems/json-jwt).

With something like this we could get rid of needing to include a second JWT dependency in the mix.

Currently this only supports RSA keys, but could easily be extended if considered a good approach.

@sourcelevel-bot
Copy link

Hello, @anakinj! This is your first Pull Request that will be reviewed by Ebert, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information.

lib/jwt/jwk.rb Outdated Show resolved Hide resolved
lib/jwt/jwk.rb Outdated Show resolved Hide resolved
lib/jwt/decode.rb Outdated Show resolved Hide resolved
lib/jwt/decode.rb Outdated Show resolved Hide resolved
lib/jwt/decode.rb Outdated Show resolved Hide resolved
lib/jwt/decode.rb Outdated Show resolved Hide resolved
lib/jwt/jwk.rb Outdated Show resolved Hide resolved
lib/jwt/jwk.rb Outdated Show resolved Hide resolved
lib/jwt/jwk.rb Outdated Show resolved Hide resolved
lib/jwt/jwk.rb Outdated Show resolved Hide resolved
lib/jwt/decode.rb Outdated Show resolved Hide resolved
lib/jwt/decode.rb Outdated Show resolved Hide resolved
lib/jwt/decode.rb Outdated Show resolved Hide resolved
lib/jwt/jwk.rb Outdated Show resolved Hide resolved
lib/jwt/jwk.rb Outdated Show resolved Hide resolved
lib/jwt/jwk.rb Outdated Show resolved Hide resolved
lib/jwt/jwk_key_finder.rb Outdated Show resolved Hide resolved
lib/jwt/jwk_key_finder.rb Outdated Show resolved Hide resolved
lib/jwt/jwk_key_finder.rb Outdated Show resolved Hide resolved
lib/jwt/jwk_key_finder.rb Outdated Show resolved Hide resolved
@sourcelevel-bot
Copy link

Ebert has finished reviewing this Pull Request and has found:

  • 1 possible new issue (including those that may have been commented here).

You can see more details about this review at https://ebertapp.io/github/jwt/ruby-jwt/pulls/289.

@excpt excpt self-requested a review December 2, 2018 21:29
@excpt excpt self-assigned this Dec 2, 2018
@excpt
Copy link
Member

excpt commented Dec 3, 2018

Hi @anakinj,

thanks for the PR! This looks very good.

It would be great if you could include an update in the README.md that JWK is supported for RSA keys.

Please ignore the build errors in travis. This seems to be related to the used OpenSSL version in the containers.

@anakinj
Copy link
Member Author

anakinj commented Dec 3, 2018

Hi @excpt.

Thanks for the feedback. I'll do something related to the documentation and was also thinking to add support for EC public keys.

It seems that the Travis build failure is because Ruby 2.2 does not support the openssl gem specified in the gemspec. Maybe we could just drop Ruby 2.2 support (drop the build), the road for ruby 2.2 is ending anyway (https://www.ruby-lang.org/en/news/2018/06/20/support-of-ruby-2-2-has-ended/).

def initialize(options)
jwks_or_loader = options[:jwks]
@jwks = jwks_or_loader if jwks_or_loader.is_a?(Hash)
@jwk_loader = jwks_or_loader if jwks_or_loader.respond_to?(:call)

Choose a reason for hiding this comment

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

JWT::JWK::KeyFinder#initialize manually dispatches method call

Copy link
Member Author

Choose a reason for hiding this comment

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

I would not like to have the same thing given as two different parameters, therefore the check if it's lazy-loadable or not.

@anakinj anakinj force-pushed the jwk-support branch 2 times, most recently from 55a2d06 to 417e32c Compare December 3, 2018 21:31
@anakinj
Copy link
Member Author

anakinj commented Dec 3, 2018

Got some time to refactor this, moved the JWK related things into its own module and separated the RSA handling to a completely own class. Also added a code example to the README.md.

Did not add the EC support just yet, i did not quite understand how the parameters should be represented for those keys.

@anthonylebrun
Copy link

Sweet! Thanks @anakinj for working on this. Is this just pending review atm?

@anakinj
Copy link
Member Author

anakinj commented Jan 12, 2019

@anthonylebrun, I have nothing pending related to this anymore. Additional algorithms and such can be added later, if there is a need for it.

@excpt excpt merged commit be86168 into jwt:master Jan 17, 2019
@joelvh
Copy link

joelvh commented Jan 17, 2019

Great to see this merged. When will it be released?

@bethesque
Copy link

Also keen to have this released!

@bjeanes
Copy link

bjeanes commented Mar 26, 2019

Just wanted to drop in here and thank @anakinj and everyone that helped get this over the line. I just used this in a new integration and found it really straight forward to decode JWTs and validate with JWKs. 🙏 thank you for allowing the JWKs to be loaded from a .call-able too!

@anakinj
Copy link
Member Author

anakinj commented Mar 27, 2019

Great to hear that this giving value and thank you for the kind words @bjeanes

@excpt
Copy link
Member

excpt commented Apr 2, 2019

@joelvh
Copy link

joelvh commented Apr 18, 2019

Thanks @excpt !

@bethesque
Copy link

Thanks! We've been using the gem from github source and it's been working well for us. Thanks for your work on this.

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

Successfully merging this pull request may close these issues.

None yet

6 participants