Last active
May 26, 2021 10:42
-
-
Save souhaiebtar/079b6dceee62983c90379d0873f41c40 to your computer and use it in GitHub Desktop.
[decrypt JWT] js function to decrypt JWT tokent #js #javascript
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
function decryptJwt (token) { | |
let base64Url = token.split('.')[1]; | |
let base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); | |
let jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) { | |
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | |
}).join('')); | |
return JSON.parse(jsonPayload); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment