-
Notifications
You must be signed in to change notification settings - Fork 376
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
Support for JWK in-lieu of rsa_public #158
Comments
Maybe using json-jwt's JWK implementation is the fastest path? |
@caldwecr yes, but I believe they are susceptible to https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/ as the library does not require specifying an algorithm. Would be good if this library were to implement it. |
In case anyone (like me) came across this issue while trying to implement AWS Cognito, here is a solution that uses the json-jwt gem instead of Node + filesystem as in the above example.
|
Quick question @dmdeller, what if I have multiple keys in the Do i need to then loop upon the Or there is a better way of doing that? |
Hi @rahulbajaj0509 , I was able to easily validate keys by using KEYS = [
{
alg: "RS256",
e: "AQAB",
kid: "ZZmKb1+XXXXXX",
kty: "RSA",
n: "XXXXXXXXXX",
use: "sig"
},
{
alg: "RS256",
e: "AQAB",
kid: "rFjv01poeXXXXXXX",
kty: "RSA",
n: "XXXXXXXX",
use: "sig"
}
]
JWT.decode(jwt_token, nil, true, { algorithms: ['RS256'], jwks: { keys: KEYS } }) In any case, check: https://github.com/jwt/ruby-jwt/#json-web-key-jwk |
It's interesting to note in the example above that the decode function is expecting the keys as a hash of symbols. (I realize its defined like that above but I still figured it would be smart enough to differentiate) This means fetching your jwks keys from a public endpoint which returns a hash of string keys will not work. Something like.. keys = HTTParty.get(ENV['JWKS_URL']) # { "keys": [{ "kid": "..." }, ...]}
JWT.decode(jwt_token, nil, true, { algorithms: ['RS256'], jwks: keys }) will throw a key not found error or something similar. Where as.. keys = HTTParty.get(ENV[''JWKS_URL']) # { "keys": [{ "kid": "..." }, ...]}
JWT.decode(jwt_token, nil, true, { algorithms: ['RS256'], jwks: keys.deep_symbolize_keys! }) # Note deep_symbolize_keys is a rails active support function. Will work. Took me a while to figure out why I was seeing that error. Hope that saves someone some time. |
JWKs are now a part of the gems and the symbol vs keys in addressed in the next release. Closing this now. Feel free to open new issues with suggestions for future improvements are welcome. |
It didn't work unless you symbolize the name of the keys, thx for the hints above, in my case I used this (in case someone else follows the same path):
|
So AWS Cognito User Pools went GA today. Working through a lot of the details. In particular the process of verifying the integrity of the Id and Access token types that Cognito returns. Both of these are JWT tokens and can ultimately be verified using ruby-jwt - BUT to do that requires first converting the JWK format that Amazon provides the Cognito public keys for an individual AWS account's UserPool.
Here were the steps I ended up following ...
decoded_token = JWT.decode token, rsa_public, true, algorithm: 'RS256'
So a couple things -
The text was updated successfully, but these errors were encountered: