Last active
August 28, 2020 19:02
-
-
Save bitsapien/efabb27c29b40a34570d09fe48875c09 to your computer and use it in GitHub Desktop.
Single line JWT decoder
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
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