Created
June 28, 2016 10:10
-
-
Save marklagendijk/11734b954a986c4420cc20d33ef19757 to your computer and use it in GitHub Desktop.
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
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