Support int and float for numeric date in JWT
Fixes
@@ -165,7 +165,7 @@ class JWTClaims(BaseClaims):
"""
if 'exp' in self:
exp = self['exp']
- if not isinstance(exp, int):
+ if not _validate_numeric_time(exp):
raise InvalidClaimError('exp')
if exp < (now - leeway):
raise ExpiredTokenError()
@@ -181,7 +181,7 @@ class JWTClaims(BaseClaims):
"""
if 'nbf' in self:
nbf = self['nbf']
- if not isinstance(nbf, int):
+ if not _validate_numeric_time(nbf):
raise InvalidClaimError('nbf')
if nbf > (now + leeway):
raise InvalidTokenError()
@@ -194,7 +194,7 @@ class JWTClaims(BaseClaims):
"""
if 'iat' in self:
iat = self['iat']
- if not isinstance(iat, int):
+ if not _validate_numeric_time(iat):
raise InvalidClaimError('iat')
def validate_jti(self):
@@ -208,3 +208,7 @@ class JWTClaims(BaseClaims):
sensitive string. Use of this claim is OPTIONAL.
"""
self._validate_claim_value('jti')
+
+
+def _validate_numeric_time(s):
+ return isinstance(s, (int, float))
