Skip to content

jwk construct with hs256 returns 'k' as binary #137

@piedrahitapablo

Description

@piedrahitapablo

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions