Skip to content

Instantly share code, notes, and snippets.

@bitsapien
Last active August 28, 2020 19:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bitsapien/efabb27c29b40a34570d09fe48875c09 to your computer and use it in GitHub Desktop.
Single line JWT decoder
exports.jwtDecode = jwtToken =>
JSON.parse(Buffer.from(jwtToken.split(".")[1], "base64").toString("utf-8"));
/* Usage:
* jwtDecode('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c');
* => {
* "sub": "1234567890",
* "name": "John Doe",
* "iat": 1516239022
* }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment