Skip to content

Commit 2266973

Browse files
committed
Do not fail in JWT decode() if at_hash claim is missing
Fixes #75
1 parent 28cc671 commit 2266973

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

jose/jwt.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,11 @@ def _validate_at_hash(claims, access_token, algorithm):
420420
"""
421421
if 'at_hash' not in claims and not access_token:
422422
return
423+
elif access_token and 'at_hash' not in claims:
424+
return
423425
elif 'at_hash' in claims and not access_token:
424426
msg = 'No access_token provided to compare against at_hash claim.'
425427
raise JWTClaimsError(msg)
426-
elif access_token and 'at_hash' not in claims:
427-
msg = 'at_hash claim missing from token.'
428-
raise JWTClaimsError(msg)
429428

430429
try:
431430
expected_hash = calculate_at_hash(access_token,

tests/test_jwt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ def test_at_hash_missing_access_token(self, claims, key):
468468

469469
def test_at_hash_missing_claim(self, claims, key):
470470
token = jwt.encode(claims, key)
471-
with pytest.raises(JWTError):
472-
jwt.decode(token, key, access_token='<ACCESS_TOKEN>')
471+
payload = jwt.decode(token, key, access_token='<ACCESS_TOKEN>')
472+
assert 'at_hash' not in payload
473473

474474
def test_at_hash_unable_to_calculate(self, claims, key):
475475
token = jwt.encode(claims, key, access_token='<ACCESS_TOKEN>')

0 commit comments

Comments
 (0)