Last active
June 9, 2020 13:06
-
-
Save adamtarmstrong/42f9f7222761ffc0770021f3a64b6345 to your computer and use it in GitHub Desktop.
Decode JWT in Axway Titanium
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
/** | |
* 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