Keats / jsonwebtoken

JWT lib in rust
MIT License
1.64k stars 260 forks source link

Would it be possible to add `DecodingKey::from_jwk` #260

Closed LLBlumire closed 1 year ago

LLBlumire commented 2 years ago

It seems a very common pattern is to have a JwkSet be published by API providers, the most common thing to do with this is use the data from it to verify, so having DecodingKey::from_jwk, or maybe even a validate method that just takes a token &str and a JwkSet and does the "common happy path" operation, might be a nice API to have?

Keats commented 2 years ago

I'm not sure it would be much simpler than https://github.com/Keats/jsonwebtoken/blob/master/examples/auth0.rs where you can easily tweak everything.

LLBlumire commented 2 years ago

I guess my thoughts were something that covers more than just the RSA case, though that is definitely the most common

Jonathas-Conceicao commented 1 year ago

I would also like to see the library support this, as mentioned previously, the current API only directly supports RSA JWK. Where one can do DecodingKey::from_rsa_components.

The same, however, can't be done for the other algorithms as, e.g., there is no way to generate a DecodingKey from EC X, Y and curve parameters. And Ideally I believe there should be an from_jwk, ans it would simplify validating the payload without explicitly checking the exactly algorithm on the JWK.

Keats commented 1 year ago

It would need to come as a PR