-
Notifications
You must be signed in to change notification settings - Fork 49
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
Parse time claims as Number and convert to Long. #759
Conversation
Follow-up to #758 |
...ntation/jwt-auth/src/main/java/io/smallrye/jwt/auth/principal/DefaultJWTCallerPrincipal.java
Outdated
Show resolved
Hide resolved
@nelsongraca You can take a look at the DefaultJWTCallerPrincipalTest class. You can try to write a test by adding a claim |
I looked into it but seems like I'll have to write a full JWT JSON to parse, or did I miss anything? |
@nelsongraca You can copy and paste a test like this one: https://github.com/smallrye/smallrye-jwt/blob/main/testsuite/basic/src/test/java/io/smallrye/jwt/auth/principal/DefaultJWTParserTest.java#L39, and set the claim in the token which is generated (see for ex, https://github.com/smallrye/smallrye-jwt/pull/758/files#diff-54a6e9144bee33f11a541e8e1ce7978cc8c1ce3cd8ed8599b5fa89d02b44bd73) and assert it is available in the parsed token |
@nelsongraca Ignore my comment please, easier to copy one of the test resources, indeed |
b2bc818
to
73aac69
Compare
@Skyllarr and @sberyozkin added test for some of the time claims, only question is regarding best practice/convention, should I use static time, or dynamically with current time, both ways are in the code (one of the commented out), LMK which should be used. |
@nelsongraca Thanks, this is probably not testing the fix the best way. Rather than modifying this legacy test code, can you please copy |
@sberyozkin yep can do it. |
73aac69
to
16c01d9
Compare
Still need to move it to a new class, can't load from JSON though This is the original reason I'm not using a JSON with the claims, if there's something I'm missing or I'm not clear enough let me know. |
@nelsongraca Token verification step can be skipped for the test, since it is about asserting the parser correctly handles the JSON containing such claims, the verification has already happened at this stage. |
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.
The test can be made simpler, but it covers the fix, thanks @nelsongraca
is there a date set when a version with this fix will be released? |
When integrating with Jetbrains Hub as an OpenID provider, found that it returns the time fields in the JWT as seconds since epoch and miliseconds in the decimal part.
Example:
This was causing a
org.jose4j.jwt.MalformedClaimException
to be thrown asDouble
can't be cast toLong
at first sight this seems a bug in the OpenID provider, but the spec is vague about the definition.There is no specific mention that the value has to be
Long
.This PR aims to prevent such cases by getting the
Claim
asNumber
and then returning it as aLong
Further information can be found on the Zulip thread: https://quarkusio.zulipchat.com/#narrow/stream/187030-users/topic/The.20value.20of.20the.20'exp'.20claim.20is.20not.20the.20expected.20type
Tests not added yet as I'm unsure how I can write such test.