-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add clockTimestamp option to .verify() you can set the current time in seconds with it #274
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
Conversation
I am okay with this but is there a better name than |
Sure, anything you like. Just |
Can I speed this up somehow? Should I just change it to timestamp? |
Hi @mborst, sorry for the delay.
|
No problem!
But I don't think it's a good idea to allow milliseconds anywhere, to be honest. Basically every other thing is in seconds, specifically the specified fields of the JWT itself. Using ms somewhere could give users a wrong impression and one would have to check the code to see how rounding is handled behind the scenes. |
Ok, I buy your thought, let's leave the seconds.
|
Oh, sorry for forgetting the checks. Added them now. In general, are you open towards a bit of clean-up work in the test suite? Also, are you open to introducing linting and some other things? Side note: I couldn't reproduce the token I changed on my system with what I assumed to be the same parameters, even though I was able to verify it. I'm not well versed in cryptography, but that struck me as odd. |
Oh, one more thing, I am not sure if the
|
Yep, it could break some usage. That's why I suggested this ugly line: Basically instead of reusing the variable you used you have to use it directly (you can create a variable right there and add a comment about why you can't reuse the Still... people with current usage if they want to use
Can you think in any other option? |
I think you covered everything. |
README.md
Outdated
@@ -117,6 +117,7 @@ encoded public key for RSA and ECDSA. | |||
* `ignoreNotBefore`... | |||
* `subject`: if you want to check subject (`sub`), provide a value here | |||
* `clockTolerance`: number of seconds to tolerate when checking the `nbf` and `exp` claims, to deal with small clock differences among different servers | |||
* `clockTimestamp`: the time in seconds that should be assumed as the current time for all necessary comparisons (also against `maxAge`) |
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 think you would need to explicitly say something like also against maxAge, be sure you don't use milliseconds in maxAge when you use both together, since clockTimestamp works with seconds
.
I just realized we don't have docs for maxAge
, we could add it (now or later) suggesting the use of second as minimum unit just for common sense, warning that in the future it could be the minimum unit.
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.
Fixed and added.
Thanks @mborst !! I need to give a look other PRs and I may create a minor version with this and other changes soon. |
@mborst I just released a minor version |
This PR enables passing a value
now
to the verify function that is then used instead ofDate.now()
(or ratherMath.floor(Date.now()/1000
).Tackles #240.
I didn't change the logic of
options.maxAge
because it uses milli seconds which seemed weird to use as a unit foroptions.now
. (See #273)