Skip to content

Instantly share code, notes, and snippets.

@marklagendijk
Created June 28, 2016 10:10
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 marklagendijk/11734b954a986c4420cc20d33ef19757 to your computer and use it in GitHub Desktop.
Save marklagendijk/11734b954a986c4420cc20d33ef19757 to your computer and use it in GitHub Desktop.
var jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0b3B0YWwuY29tIiwiZXhwIjoxNDI2NDIwODAwLCJodHRwOi8vdG9wdGFsLmNvbS9qd3RfY2xhaW1zL2lzX2FkbWluIjp0cnVlLCJjb21wYW55IjoiVG9wdGFsIiwiYXdlc29tZSI6dHJ1ZX0.yRQYnWzskCZUxPwaQupWkiUzKELZ49eM7oWxAQK_ZXw';
console.log(decodeJsonWebToken(jwt));
function decodeJsonWebToken(token){
var tokenParts = token.split('.');
return {
header: decodeTokenPart(tokenParts[0]),
token: decodeTokenPart(tokenPart[1]),
signature: tokenPart[2]
};
}
function decodeTokenPart(tokenPart){
tokenPart = Base64.decode(tokenPart);
return JSON.parse(tokenPart);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment