Skip to content

Commit

Permalink
Return tokens as string not bytes (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpadilla authored Aug 24, 2020
1 parent d926a4d commit 5d33b04
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Usage
>>> import jwt
>>> encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg'
>>> print(encoded)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg
>>> jwt.decode(encoded, 'secret', algorithms=['HS256'])
{'some': 'payload'}
Expand Down
5 changes: 3 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ Example Usage
-------------

.. code-block:: python
.. doctest::

>>> import jwt

>>> encoded_jwt = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
>>> encoded_jwt
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg'
>>> print(encoded_jwt)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg

>>> jwt.decode(encoded_jwt, 'secret', algorithms=['HS256'])
{'some': 'payload'}
Expand Down
4 changes: 3 additions & 1 deletion jwt/api_jws.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ def encode(

segments.append(base64url_encode(signature))

return b".".join(segments)
encoded_string = b".".join(segments)

return encoded_string.decode("utf-8")

def decode(
self,
Expand Down

0 comments on commit 5d33b04

Please sign in to comment.