Skip to content

Instantly share code, notes, and snippets.

@zema1
Last active July 20, 2018 06:47
Show Gist options
  • Save zema1/f050784ebbc90231c60e6b9ece9eb9cd to your computer and use it in GitHub Desktop.
Save zema1/f050784ebbc90231c60e6b9ece9eb9cd to your computer and use it in GitHub Desktop.
simple jwt token encode and decode
```
def base64_url_encode(text):
return base64.b64encode(text).replace('+', '-').replace('/', '_').replace('=', '')
def base64_url_decode(text):
text = text.replace('-', '+').replace('_', '/')
while True:
try:
result = base64.b64decode(text)
except TypeError:
text += '='
else:
break
return result
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment