Created
April 13, 2018 16:15
-
-
Save yarkovaleksei/2a89ad165da99b577e598bc4fdd3893c to your computer and use it in GitHub Desktop.
Decode jwt token
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
function parseJwt (token) { | |
const base64Url = token.split('.')[1] | |
const base64 = base64Url.replace('-', '+').replace('_', '/') | |
return JSON.parse(window.atob(base64)) | |
} | |
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVhNGQxMWExNjQ0ZWZmMDAwMTI0ZjA1ZiIsImlhdCI6MTUyMzYzNTgyOSwiZXhwIjoxNTIzNzIyMjI5fQ.Vhfcry3B9fqP1MmZ9Sz_VZK8FfVOwQ72MoGyvR0idNU' | |
console.clear() | |
console.log(parseJwt(token)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment