Skip to content

Instantly share code, notes, and snippets.

@ewliang
Created February 28, 2020 17:11
Show Gist options
  • Save ewliang/0c0043682a20d2c7cdb632bff9b2e379 to your computer and use it in GitHub Desktop.
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)
// 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