Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What format is the exp (Expiration Time) claim in a JWT

I am using ADAL library to get access token for a resource. Does anyone know what format is the expiration time in ? more specifically "exp" (Expiration time) claim.

JwtSecurityToken class simply returns int32 after parsing. So, that is not a good indicator.

Tried parsing it to TimeSpan and DateTime but the values are not 90 minutes apart. It's almost the same.

This is what I get from fiddler for iat and exp claim (used https://jwt.io/ to parse the token)

iat: 1475874457

exp: 1475878357

The values are not that much apart.

like image 780
Frank Q. Avatar asked Oct 07 '16 21:10

Frank Q.


People also ask

What is exp in JWT token?

The “exp” (expiration time) claim identifies the expiration time on or after which the JWT MUST NOT be accepted for processing. The processing of the “exp” claim requires that the current date/time MUST be before the expiration date/time listed in the “exp” claim.

Is JWT expiration time in seconds?

The JWT access token is only valid for a finite period of time. Using an expired JWT will cause operations to fail. As you saw above, we are told how long a token is valid through expires_in . This value is normally 1200 seconds or 20 minutes.

How can JWT token expire time?

You can use a lib(like jwt_decode) to decode your JWT token, where it's most likely contains an expiration timestamp that you can check(compare it with the current timestamp for this moment) and if it exceeded(expired) just delete it from local storage and redirect user to login page.

How do I check my JWT expiry date?

verify method to a function that returns a promise and assign it to jwtVerifyAsync . Then we call jwtVerifyAsync with the token and the token secret to check if the token is valid. If it's expired, then it's considered invalid and an error will be thrown.


2 Answers

RFC 7519 states that the exp and iat claim values must be NumericDate values.

NumericDate is the last definition in Section 2. Terminology, and is defined as the number of seconds (not milliseconds) since Epoch:

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. This is equivalent to the IEEE Std 1003.1, 2013 Edition [POSIX.1] definition "Seconds Since the Epoch", in which each day is accounted for by exactly 86400 seconds, other than that non-integer values can be represented. See RFC 3339 [RFC3339] for details regarding date/times in general and UTC in particular.

like image 99
Les Hazlewood Avatar answered Oct 05 '22 20:10

Les Hazlewood


Les provided the right answer. If you want to quickly convert a NumericDate to a date, you can do it using the following PowerShell command:

$numericDate = '1636027948' ([DateTime]('1970,1,1')).AddSeconds($numericDate) 

Output:

Thursday, 4 November 2021 12:12:28 
like image 34
Martin Brandl Avatar answered Oct 05 '22 18:10

Martin Brandl