Home:ALL Converter>Library for decoding JWT on client-side

Library for decoding JWT on client-side

Ask Time:2016-10-13T02:31:18         Author:KMC

Json Formatter

I'm working on a website that stores JWT token inside cookies. What I want to do is, create Javascript that decodes the token and extracts the value I need and pass it on to the another Javascript written by my co-worker. My question is, is there client-side javascript library for JWT token decoding that I can import from my script?

Author:KMC,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40005902/library-for-decoding-jwt-on-client-side
bhspencer :

EDIT: It has come to my attention that this answer is incorrect. Please see this answer instead\nHow to decode jwt token in javascript without using a library?\nA JWT is just a dot separated base64 encoded string. You just need to split on the dots and then use atob() to decode. You don't need an external library.\ne.g.\n\r\n\r\nvar jwt = \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ\";\n\nvar tokens = jwt.split(\".\");\n\nconsole.log(JSON.parse(atob(tokens[0])));\nconsole.log(JSON.parse(atob(tokens[1])));",
2016-10-12T19:11:04
yy