-
Notifications
You must be signed in to change notification settings - Fork 252
Closed
Labels
Description
Not sure if this is expected behavior or a minor bug, but when jwk.construct
is used and the jwk is converted to a dict using .to_dict
, the 'k' attribute is returned as a binary string. This is not an issue until the dict is used to decode a JWT and an AttributeError is raised because 'k' does not have a encode
method ('bytes' object has no attribute 'encode'). To reproduce:
from jose import jwk, jwt
user_jwt = jwt.encode({'username': 'user'}, 'secret')
jwk_obj = jwk.construct('secret', 'HS256')
jwk_dict = jwk_obj.to_dict()
# to avoid the exception:
# jwk_dict['k'] = jwk_dict['k'].decode('utf-8')
claims = jwt.decode(user_jwt, jwk_dict)