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 Sign operation
|
|
|
|
*/
|
|
|
|
class JWTSign extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JWTSign constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "JWT Sign";
|
|
|
|
this.module = "Crypto";
|
|
|
|
this.description = "Signs a JSON object as a JSON Web Token using a provided secret / private key.";
|
|
|
|
this.infoURL = "https://jwt.io/";
|
|
|
|
this.inputType = "JSON";
|
|
|
|
this.outputType = "string";
|
|
|
|
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"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Signing Algorithm",
|
2018-08-29 22:43:10 +01:00
|
|
|
type: "option",
|
2018-08-26 23:16:13 +01:00
|
|
|
value: [
|
2018-08-29 22:43:10 +01:00
|
|
|
"HS256",
|
|
|
|
"HS384",
|
|
|
|
"HS512",
|
|
|
|
"RS256",
|
|
|
|
"RS384",
|
|
|
|
"RS512",
|
|
|
|
"ES256",
|
|
|
|
"ES384",
|
|
|
|
"ES512",
|
|
|
|
"None"
|
2018-08-26 23:16:13 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {JSON} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
run(input, args) {
|
|
|
|
const [key, algorithm] = args;
|
|
|
|
return jwt.sign(input, key, { algorithm: algorithm === "None" ? "none" : algorithm });
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default JWTSign;
|