Skip to content

Instantly share code, notes, and snippets.

@milksense
Created March 29, 2022 23:29
Show Gist options
  • Save milksense/37457f6a49f5555af1f3da694eed1cf6 to your computer and use it in GitHub Desktop.
Save milksense/37457f6a49f5555af1f3da694eed1cf6 to your computer and use it in GitHub Desktop.
JWT Decoder written in TypeScript [pasted]
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