Usage Examples — PyJWT 2.1.0 documentation | jwt decode python
TheJWTspecificationdefinessomeregisteredclaimnamesanddefineshowtheyshouldbeused.PyJWTsupportstheseregisteredclaimnames:ExpirationTimeClaim(exp)The“exp”(expirationtime)claimidentifiestheexpirationtimeonorafterwhichtheJWTMUSTNOTbeacceptedforprocessing.Theprocessingofthe“exp”claimrequiresthatthecurrentdate/timeMUSTbebeforetheexpirationdate/timelistedinthe“exp”claim.ImplementersMAYprovideforsomesmallleeway,usuallynomorethanafewminutes,toaccountforclockskew.ItsvalueMUSTbeanumbercontainingaNumeric...
The JWT specification defines some registered claim names and defines how they should be used. PyJWT supports these registered claim names:
Expiration Time Claim (exp)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. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew. Its value MUST be a number containing a NumericDate value. Use of this claim is OPTIONAL.
You can pass the expiration time as a UTC UNIX timestamp (an int) or as a datetime, which will be converted into an int. For example:
jwt.encode({"exp": 1371720939}, "secret") jwt.encode({"exp": datetime.now(tz=timezone.utc)}, "secret")Expiration time is automatically verified in jwt.decode() and raises jwt.ExpiredSignatureError if t...