2018-08-26 23:16:13 +01:00
|
|
|
/**
|
|
|
|
* @author gchq77703 []
|
|
|
|
* @copyright Crown Copyright 2018
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Operation from "../Operation";
|
|
|
|
import jwt from "jsonwebtoken";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JWT Verify operation
|
|
|
|
*/
|
|
|
|
class JWTVerify extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JWTVerify constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "JWT Verify";
|
|
|
|
this.module = "Crypto";
|
|
|
|
this.description = "Verifies that a JSON Web Token is valid and has been signed with the provided secret / private key.";
|
|
|
|
this.infoURL = "https://jwt.io/";
|
|
|
|
this.inputType = "string";
|
|
|
|
this.outputType = "JSON";
|
|
|
|
this.args = [
|
|
|
|
{
|
|
|
|
name: "Private / Secret Key",
|
2018-08-29 22:43:10 +01:00
|
|
|
type: "text",
|
2018-08-26 23:16:13 +01:00
|
|
|
value: "secret_cat"
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
run(input, args) {
|
|
|
|
const [key] = args;
|
|
|
|
|
|
|
|
try {
|
2018-08-29 22:43:10 +01:00
|
|
|
return jwt.verify(input, key, { algorithms: [
|
|
|
|
"HS256",
|
|
|
|
"HS384",
|
|
|
|
"HS512",
|
|
|
|
"none"
|
|
|
|
]});
|
2018-08-26 23:16:13 +01:00
|
|
|
} catch (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default JWTVerify;
|