Created
April 20, 2022 04:59
-
-
Save catwhocode/d7d2b7904ed43facf2cd71e2dbe500d1 to your computer and use it in GitHub Desktop.
JS: Decode JWT without library
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
/* taken from: */ | |
/* https://stackoverflow.com/questions/38552003/how-to-decode-jwt-token-in-javascript-without-using-a-library?noredirect=1&lq=1 */ | |
const token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImp0aSI6ImU3YjQ0Mjc4LTZlZDYtNDJlZC05MTZmLWFjZDQzNzhkM2U0YSIsImlhdCI6MTU5NTg3NzUxOCwiZXhwIjoxNTk1ODgxMTE4fQ.WXyDlDMMSJAjOFF9oAU9JrRHg2wio-WolWAkAaY3kg4'; | |
const tokenDecodablePart = token.split('.')[1]; | |
const decoded = Buffer.from(tokenDecodablePart, 'base64').toString(); | |
console.log(decoded) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment