Skip to content

Commit b935efb

Browse files
committed
Fix for issue jasonjoh#2
Python 2.* returns an error when calling urlsafe_b64decode with a byte string. It must be encoded as utf-8 before passing the string.
1 parent 8e52082 commit b935efb

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Add a new function `get_user_email_from_id_token` to `authhelper.py`.
264264
encoded_token += '='
265265
266266
# URL-safe base64 decode the token parts
267-
decoded = base64.urlsafe_b64decode(encoded_token).decode('utf-8')
267+
decoded = base64.urlsafe_b64decode(encoded_token.encode('utf-8').decode('utf-8')
268268
269269
# Load decoded token into a JSON object
270270
jwt = json.loads(decoded)

tutorial/authhelper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def get_user_email_from_id_token(id_token):
6666
encoded_token += '='
6767

6868
# URL-safe base64 decode the token parts
69-
decoded = base64.urlsafe_b64decode(encoded_token).decode('utf-8')
69+
# NOTE: Per issue #2, added additional encode('utf-8') call on
70+
# encoded_token so this call will work in Python 2.*
71+
decoded = base64.urlsafe_b64decode(encoded_token.encode('utf-8')).decode('utf-8')
7072

7173
# Load decoded token into a JSON object
7274
jwt = json.loads(decoded)

0 commit comments

Comments
 (0)