-
-
Save brentonhouse/f9aec4e57d9ab1c679af1a40faf77406 to your computer and use it in GitHub Desktop.
Decode JWT in Axway Titanium
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
/** | |
* 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