This commit is contained in:
co98357 2025-05-23 11:30:49 +00:00 committed by GitHub
commit d8360d4da0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 83 additions and 9 deletions

View file

@ -25,7 +25,13 @@ class JWTDecode extends Operation {
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token";
this.inputType = "string";
this.outputType = "JSON";
this.args = [];
this.args = [
{
name: "Include header",
type: "boolean",
value: false
}
];
this.checks = [
{
pattern: "^ey([A-Za-z0-9_-]+)\\.ey([A-Za-z0-9_-]+)\\.([A-Za-z0-9_-]+)$",
@ -42,12 +48,17 @@ class JWTDecode extends Operation {
*/
run(input, args) {
try {
const headerInclude = args[0];
const decoded = jwt.decode(input, {
json: true,
complete: true
});
if (headerInclude) {
return {header: decoded.header, payload: decoded.payload};
} else {
return decoded.payload;
}
} catch (err) {
throw new OperationError(err);
}

View file

@ -47,5 +47,68 @@ TestRegister.addTests([
args: [],
}
],
},
{
name: "JWT Decode: HS",
input: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.0ha6-j4FwvEIKPVZ-hf3S_R9Hy_UtXzq4dnedXcUrXk",
expectedOutput: JSON.stringify({
header: {
alg: "HS256",
typ: "JWT"
},
payload: {
String: "SomeString",
Number: 42,
iat: 1
}
}, null, 4),
recipeConfig: [
{
op: "JWT Decode",
args: [true],
}
],
},
{
name: "JWT Decode: RS",
input: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.MjEJhtZk2nXzigi24piMzANmrj3mILHJcDl0xOjl5a8EgdKVL1oaMEjTkMQp5RA8YrqeRBFaX-BGGCKOXn5zPY1DJwWsBUyN9C-wGR2Qye0eogH_3b4M9EW00TPCUPXm2rx8URFj7Wg9VlsmrGzLV2oKkPgkVxuFSxnpO3yjn1Y",
expectedOutput: JSON.stringify({
header: {
alg: "RS256",
typ: "JWT"
},
payload: {
String: "SomeString",
Number: 42,
iat: 1
}
}, null, 4),
recipeConfig: [
{
op: "JWT Decode",
args: [true],
}
],
},
{
name: "JWT Decode: ES",
input: "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.WkECT51jSfpRkcpQ4x0h5Dwe7CFBI6u6Et2gWp91HC7mpN_qCFadRpsvJLtKubm6cJTLa68xtei0YrDD8fxIUA",
expectedOutput: JSON.stringify({
header: {
alg: "ES256",
typ: "JWT"
},
payload: {
String: "SomeString",
Number: 42,
iat: 1
}
}, null, 4),
recipeConfig: [
{
op: "JWT Decode",
args: [true],
}
],
}
]);

View file

@ -92,7 +92,7 @@ TestRegister.addTests([
},
{
op: "JWT Decode",
args: []
args: [false]
}
],
},
@ -107,7 +107,7 @@ TestRegister.addTests([
},
{
op: "JWT Decode",
args: []
args: [false]
}
],
},
@ -122,7 +122,7 @@ TestRegister.addTests([
},
{
op: "JWT Decode",
args: []
args: [false]
}
],
},
@ -137,7 +137,7 @@ TestRegister.addTests([
},
{
op: "JWT Decode",
args: []
args: [false]
}
],
},
@ -152,7 +152,7 @@ TestRegister.addTests([
},
{
op: "JWT Decode",
args: []
args: [false]
}
],
},
@ -167,7 +167,7 @@ TestRegister.addTests([
},
{
op: "JWT Decode",
args: []
args: [false]
}
],
}