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

Ensure presence of claims #244

Closed
curlyfingers opened this issue Oct 13, 2017 · 8 comments
Closed

Ensure presence of claims #244

curlyfingers opened this issue Oct 13, 2017 · 8 comments

Comments

@curlyfingers
Copy link

Good day,
Is there a way to check for presence of particular claims when decoding JWT.

Sample scenario:
JWT is used as request signature & expiration flag. Exp claim cannot fail if there is no such claim in payload. Is there a way to ensure presence of said exp claim within payload?

@excpt
Copy link
Member

excpt commented Oct 25, 2017

Currently there is no option enforcing presence of a token. This is something that has to be implemented system specific. After decoding a token the payload is returned and it is possible to look for the presence of tokens.

Example:

payload, header = JWT.decode token, secret, true, 'HS256'

payload.include?('exp')
# false

@excpt
Copy link
Member

excpt commented Mar 22, 2018

@AlexPatrasco Did you try implementing the suggested code?

@curlyfingers
Copy link
Author

@excpt Hi. Yes, we did implement similar logic in our project and we do raise an error since our flow relies on the presence of this particular claim.
But, perhaps, it is indeed project specific and therefore does not need to be forced

@RootTJNII
Copy link

I'd also like to +1 this. It would be nice to pass in an array of standard claims and treat the token as invalid if they're not present. This will allow for cleaner server-side control of what constitutes a valid token for the application.

@rabajaj0509
Copy link
Contributor

I would like to work on this one. Is it possible to assign this issue to myself?

@andyjdavis
Copy link
Contributor

I have raised a PR with a possible solution to this. Feedback welcome. #430

@andyjdavis
Copy link
Contributor

I think this issue can now be closed.

@andyjdavis
Copy link
Contributor

This issue is resolved by changes available in version 2.3.0. https://github.com/jwt/ruby-jwt/releases/tag/v2.3.0

I don't have the ability to mark this issue as closed. Is someone else able to?

@anakinj anakinj closed this as completed Nov 19, 2021
@anakinj anakinj removed this from the Version 3.0.0 milestone Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants