Skip to content

Instantly share code, notes, and snippets.

@JohnMarkT
Last active July 30, 2020 15:11
Show Gist options
  • Save JohnMarkT/c5dbc393e8af92feb453be372129309a to your computer and use it in GitHub Desktop.
Save JohnMarkT/c5dbc393e8af92feb453be372129309a to your computer and use it in GitHub Desktop.
Only performs basic validation, not verification. Returns object original JWT, unencrypted and parsed payload, and valid boolean.
function validateJWT(jwt) {
let payload = {}, valid = false
try {
[, payload] = jwt.split('.').slice(0,2).map(p => JSON.parse(atob(p)))
valid = true
} catch (error) {}
return { jwt, payload, valid }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment