Created
March 29, 2022 23:29
-
-
Save milksense/37457f6a49f5555af1f3da694eed1cf6 to your computer and use it in GitHub Desktop.
JWT Decoder written in TypeScript [pasted]
This file contains hidden or 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
const decodeJWT = (token: string): string => | |
decodeURIComponent( | |
atob(token.split(".")[1].replace("-", "+").replace("_", "/")) | |
.split("") | |
.map((c) => `%${("00" + c.charCodeAt(0).toString(16)).slice(-2)}`) | |
.join("") | |
); | |
console.log( | |
decodeJwt(` | |
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. | |
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0I | |
joxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c | |
`) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment