-
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
Pass payload to keyfinder #172
Conversation
Added check that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a view comments to your changes. If you find the time you may fix them. Otherwise the PR looks good to me.
key = yield(header) if keyfinder | ||
def signature_algorithm_and_key(header, payload, key, &keyfinder) | ||
if keyfinder | ||
key = (keyfinder.arity == 2) ? keyfinder.call(header, payload) : keyfinder.call(header) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change your code to use yield
instead of keyfinder.call (yield(header, playload)
and yield(header)
) and use a full if else
condition statement instead of your ternary conditions.
key = if keyfinder.arity == 2
yield(header, payload)
else
yield(header)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the arity check, I prefer call
to yield
, as it makes it more obvious that keyfinder
is the block being called. But I'll defer to your style.
def signature_algorithm_and_key(header, payload, key, &keyfinder) | ||
if keyfinder | ||
key = (keyfinder.arity == 2) ? keyfinder.call(header, payload) : keyfinder.call(header) | ||
raise JWT::DecodeError, 'No verification key available' unless key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code smell: There is an additional space in front of the unless
key word.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently no one likes my style of putting two spaces before postfix conditionals, but I wouldn't call it a code smell. ;)
Made style changes. |
Thanks. :) |
I have an app that I would like to authenticate to using tokens signed with HMAC (created by the app) or ECDSA (created by other companies), depending on the value of the issuer (
iss
) claim. I'm using thekeyfinder
block to implement that logic, but it needs to have thepayload
passed to it in order to find the appropriate public key for the issuer. To that end, I made a small change to pass both theheader
andpayload
tokeyfinder
, if it has arity of 2. Now my calling code looks like: