Last active
December 16, 2019 18:40
-
-
Save hallison/559582ddc74f505afdb9086a74e122f4 to your computer and use it in GitHub Desktop.
JS - Parse JWT
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 jwtDecode(token) { | |
var base64Url = token.split('.')[1]; | |
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); | |
var payload = decodeURIComponent(atob(base64).split('').map(function(c) { | |
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | |
}).join('')); | |
return JSON.parse(payload); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment