Last active
April 23, 2024 17:58
-
-
Save tiagorangel1/8db4ee6b9ef07624a66719861455332a to your computer and use it in GitHub Desktop.
JWT decoder used for Authflow
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
// 💡 Tip: need to decode with node.js? Use the @authflow-js/verify npm module | |
function decryptJWT(e) { | |
function b64(e) { | |
return decodeURIComponent(Array.prototype.map.call(atob(e), function (e) { | |
return "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2) | |
}).join("")) | |
} | |
try { | |
const r = e | |
.split(".")[0] | |
.replace("-", "+") | |
.replace("_", "/"), | |
b64 | |
c = (JSON.parse(b64(r)), e.split(".")[1].replace("-", "+").replace("_", "/")); | |
return JSON.parse(b64(c)) | |
} catch (e) { | |
throw new Error("Invalid JWT") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Possibly the encoding algorithm used in that JWT is different than the one the function tests for, apologies!