Skip to content

Commit 590f903

Browse files
committed
verify_expiration was removed too soon
- Merge with `verify_exp` option - Add deprecation warning
1 parent 06deb9f commit 590f903

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

jwt/api_jwt.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import warnings
23

34
from calendar import timegm
45
from collections import Mapping
@@ -74,6 +75,12 @@ def decode(self, jwt, key='', verify=True, algorithms=None, options=None,
7475

7576
def _validate_claims(self, payload, audience=None, issuer=None, leeway=0,
7677
options=None, **kwargs):
78+
79+
if 'verify_expiration' in kwargs:
80+
options['verify_exp'] = kwargs.get('verify_expiration', True)
81+
warnings.warn('The verify_expiration parameter is deprecated. '
82+
'Please use options instead.', DeprecationWarning)
83+
7784
if isinstance(leeway, timedelta):
7885
leeway = timedelta_total_seconds(leeway)
7986

tests/test_api_jwt.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,23 @@ def default(self, o):
419419
payload = jwt.decode(token, 'secret')
420420

421421
assert payload == {'some_decimal': 'it worked'}
422+
423+
def test_decode_with_verify_expiration_kwarg(self, jwt, payload):
424+
payload['exp'] = utc_timestamp() - 1
425+
secret = 'secret'
426+
jwt_message = jwt.encode(payload, secret)
427+
428+
pytest.deprecated_call(
429+
jwt.decode,
430+
jwt_message,
431+
secret,
432+
verify_expiration=False
433+
)
434+
435+
with pytest.raises(ExpiredSignatureError):
436+
pytest.deprecated_call(
437+
jwt.decode,
438+
jwt_message,
439+
secret,
440+
verify_expiration=True
441+
)

0 commit comments

Comments
 (0)