Added algorithm-choice support to JWT Verify

This commit is contained in:
Michael Rowley 2021-12-30 20:32:06 +00:00
parent ae1b12c120
commit 0a73825ebe

View file

@ -26,12 +26,19 @@ class JWTVerify extends Operation {
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token"; this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token";
this.inputType = "string"; this.inputType = "string";
this.outputType = "JSON"; this.outputType = "JSON";
let algOptions = JWT_ALGORITHMS.slice(0, JWT_ALGORITHMS.length - 1);
algOptions.push("Any");
this.args = [ this.args = [
{ {
name: "Public/Secret Key", name: "Public/Secret Key",
type: "text", type: "text",
value: "secret" value: "secret"
}, },
{
name: "Algorithm",
type: "option",
value: algOptions
}
]; ];
} }
@ -41,9 +48,21 @@ class JWTVerify extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const [key] = args; const [key, alg] = args;
const algos = JWT_ALGORITHMS; switch (alg) {
algos[algos.indexOf("None")] = "none"; case "Any":
const algos = JWT_ALGORITHMS;
break;
case "None":
const algos = [ "none" ];
default:
const algIndex = JWT_ALGORITHMS.indexOf(alg);
if (algIndex === -1) {
throw new OperationError("The JWT verification algorithm provided is not supported.");
}
const algos = JWT_ALGORITHMS[];
break;
}
try { try {
const verified = jwt.verify(input, key, { algorithms: algos }); const verified = jwt.verify(input, key, { algorithms: algos });