File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ def get_unverified_claims(token):
118118 token (str): A signed JWS to decode the headers from.
119119
120120 Returns:
121- dict : The dict representation of the token claims.
121+ str : The str representation of the token claims.
122122
123123 Raises:
124124 JWSError: If there is an exception decoding the token.
Original file line number Diff line number Diff line change @@ -184,6 +184,14 @@ def get_unverified_claims(token):
184184 except :
185185 raise JWTError ('Error decoding token claims.' )
186186
187+ try :
188+ claims = json .loads (claims .decode ('utf-8' ))
189+ except ValueError as e :
190+ raise JWTError ('Invalid claims string: %s' % e )
191+
192+ if not isinstance (claims , Mapping ):
193+ raise JWTError ('Invalid claims string: must be a json object' )
194+
187195 return claims
188196
189197
Original file line number Diff line number Diff line change @@ -402,3 +402,17 @@ def test_jti_invalid(self, key):
402402 token = jwt .encode (claims , key )
403403 with pytest .raises (JWTError ):
404404 jwt .decode (token , key )
405+
406+ def test_unverified_claims_string (self ):
407+ token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.aW52YWxpZCBjbGFpbQ.iOJ5SiNfaNO_pa2J4Umtb3b3zmk5C18-mhTCVNsjnck'
408+ with pytest .raises (JWTError ):
409+ jwt .get_unverified_claims (token )
410+
411+ def test_unverified_claims_list (self ):
412+ token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.WyJpbnZhbGlkIiwgImNsYWltcyJd.nZvw_Rt1FfUPb5OiVbrSYZGtWSE5c-gdJ6nQnTTBkYo'
413+ with pytest .raises (JWTError ):
414+ jwt .get_unverified_claims (token )
415+
416+ def test_unverified_claims_object (self , claims , key ):
417+ token = jwt .encode (claims , key )
418+ assert jwt .get_unverified_claims (token ) == claims
You can’t perform that action at this time.
0 commit comments