Last active
July 20, 2018 06:47
-
-
Save zema1/f050784ebbc90231c60e6b9ece9eb9cd to your computer and use it in GitHub Desktop.
simple jwt token encode and decode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
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