Skip to content

Instantly share code, notes, and snippets.

@hahwul
Created December 30, 2020 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hahwul/c33e582487a6a13bbe1ef5301275bfad to your computer and use it in GitHub Desktop.
Save hahwul/c33e582487a6a13bbe1ef5301275bfad to your computer and use it in GitHub Desktop.
Parsing JWT
function parseJwt (token) {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
var jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(jsonPayload);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment