Created
February 28, 2020 17:11
-
-
Save ewliang/0c0043682a20d2c7cdb632bff9b2e379 to your computer and use it in GitHub Desktop.
Function for Decoding JWT Tokens to Access JWT Payload via JavaScript (No Library)
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
// Decodes a JWT with JavaScript | |
function jwtDecoder(token) { | |
// 1. Split and Target the Payload Portion of the JWT Token String | |
// 2. atob() to Decode the JWT's Base64 Encoded String into Readable JSON String | |
// 3. Convert JSON String to parsable JSON Object | |
return JSON.parse(atob(token.split('.')[1])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment