/
JWTDecodeDynamicValue.js
45 lines (32 loc) · 1.13 KB
/
JWTDecodeDynamicValue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var JWTDecodeDynamicValue = function() {
this.evaluate = function(context) {
var toDecode;
var parts = this.jwt.split(".");
if(this.part === "header") {
toDecode = parts[0]
} else {
toDecode = parts[1]
}
var decoder = new DynamicValue('com.luckymarmot.Base64EncodingDynamicValue', {
"input": toDecode, "mode": 1
});
toDecode = decoder.getEvaluatedString();
if(typeof this.keypath !== "undefined" && this.keypath !== null && this.keypath !== "") {
toDecode = JSON.parse(toDecode);
var paths = this.keypath.split(".");
paths.forEach(function(path) {
toDecode = toDecode[path];
});
}
return toDecode;
}
}
JWTDecodeDynamicValue.identifier = "com.luckymarmot.PawExtensions.JWTDecodeDynamicValue";
JWTDecodeDynamicValue.title = "JWT Decode";
JWTDecodeDynamicValue.help = "https://jwt.io/"
JWTDecodeDynamicValue.inputs = [
InputField("jwt", "JWT", "String"),
InputField("part", "Decode From", "Select", {"choices": {"header": "Header", "payload": "Payload"}, defaultValue: "payload"}),
InputField("keypath", "KeyPath (optional)", "String")
]
registerDynamicValueClass(JWTDecodeDynamicValue);