python-jose icon indicating copy to clipboard operation
python-jose copied to clipboard

jws.verify returns byte, not string as documented

Open raphet opened this issue 5 years ago • 1 comments

Problem jws.verify() returns byte, not string. It's wrong in your code and it's wrong in the documentation https://python-jose.readthedocs.io/en/latest/jwk/index.html https://github.com/mpdavis/python-jose/blob/5ec9f48c1babcbfa62d433b29e55db8888c315ec/jose/jws.py#L65

Actual result

>>> token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoiYiJ9.jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8'
>>> jws.verify(token, 'secret', algorithms='HS256')
b'{"a":"b"}'

Expected result {"a":"b"}

Fix

>>> token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoiYiJ9.jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8'
>>> jws.verify(token, 'secret', algorithms='HS256').decode('utf-8)
'{"a":"b"}'

This is the second defect in your documentation I find.

raphet avatar Aug 18 '20 13:08 raphet

This is the second defect in your documentation I find.

I don't understand the point you are trying to make. All software contains bugs, and I'm sure there are more defects in our documentation.

Since this is such a simple fix, I'll wait for your pull request that fixes the documentation. Thanks! 😃

blag avatar Aug 18 '20 20:08 blag