Skip to content

Commit

Permalink
Do not fail in JWT decode() if at_hash claim is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Feb 2, 2018
1 parent 28cc671 commit 2266973
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions jose/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,11 @@ def _validate_at_hash(claims, access_token, algorithm):
"""
if 'at_hash' not in claims and not access_token:
return
elif access_token and 'at_hash' not in claims:
return
elif 'at_hash' in claims and not access_token:
msg = 'No access_token provided to compare against at_hash claim.'
raise JWTClaimsError(msg)
elif access_token and 'at_hash' not in claims:
msg = 'at_hash claim missing from token.'
raise JWTClaimsError(msg)

try:
expected_hash = calculate_at_hash(access_token,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ def test_at_hash_missing_access_token(self, claims, key):

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

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

0 comments on commit 2266973

Please sign in to comment.