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

Order of JSON key, value pairs #148

Closed
kimmobrunfeldt opened this issue Dec 10, 2015 · 1 comment
Closed

Order of JSON key, value pairs #148

kimmobrunfeldt opened this issue Dec 10, 2015 · 1 comment

Comments

@kimmobrunfeldt
Copy link

I'm not sure if this is a flaw in JWT specification or if I don't understand something. In JWT, the order of JSON key, value pairs matters when encoding and decoding tokens. Having {"alg": "HS256", "typ": "JWT"} headers produces different token compared to {"typ": "JWT", "alg": "HS256"}.

This seems weird to me because JSON specification states that the key, value pairs do not have an order: An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma). source.

jwt

Do you have an explanation for this?

@kimmobrunfeldt
Copy link
Author

Ok, I just figured out why this doesn't matter. As long as the secret is same, the token will work even though it looks different. The receiving part will use the secret to decode the token and even though the headers or payload are in different order, the end result is the same.

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

No branches or pull requests

1 participant