I'll like to create JWT exp claim style date in Javascript. My app jwt claim returns an expiry date of 1424984529. I'm doing a test for token expiration using this:
if(jwt.exp < Date.now())) {
// do something
}
As at writing Date.now() gives me 1424941329632 and jwt.exp gives 1424984529. Obviously, my test will always return true.
So my question is, how do I mimic jwt-style exp date in Javascript?
A JSON numeric value representing the number of seconds from 1970-01-01T00:00:00Z UTC until the specified UTC date/time, ignoring leap seconds.
Go to Dashboard > Applications > APIs and click the name of the API to view. Locate the Token Expiration (Seconds) field, and enter the appropriate access token lifetime (in seconds) for the API. Default value is 86,400 seconds (24 hours). Click Save Changes.
exp (expiration time): Time after which the JWT expires. nbf (not before time): Time before which the JWT must not be accepted for processing. iat (issued at time): Time at which the JWT was issued; can be used to determine age of the JWT.
Expiration time is automatically verified in jwt. decode() and raises jwt.
How about:
if (jwt.exp < Date.now() / 1000) {
// do something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With