Skip to content

Instantly share code, notes, and snippets.

@adamtarmstrong
Last active June 9, 2020 13:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adamtarmstrong/42f9f7222761ffc0770021f3a64b6345 to your computer and use it in GitHub Desktop.
Save adamtarmstrong/42f9f7222761ffc0770021f3a64b6345 to your computer and use it in GitHub Desktop.
Decode JWT in Axway Titanium
/**
* token
* claim = "registered" || "public" || "private"
*/
exports.decodeJWT = function(token, claim) {
var base64Url;
if (claim == "registered") {
base64Url = token.split('.')[0];
} else if (claim == "private") {
base64Url = token.split('.')[2];
} else {
base64Url = token.split('.')[1];
}
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
var utf8 = Ti.Utils.base64decode(base64);
var json = JSON.parse(utf8);
return json;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment