I was developing APIs that are secured with JWS of the payload. To test these APIs behind the MuleSoft/CloudHub API Manager JWS Policy (a custom policy I create, I will write another blog about it.) I needed to generate the JWS signature sent to the API policy in PostMan.
The steps are very simple
- Store the private key and KID (Key ID) in the environment variables
- load the jsrsaasign library
- Using the private key and library generate the JWS sigature
Simple enough?
var privateKey = pm.environment.get("privateKey");
if(pm.globals.get("jsrsasign-js") == null){
const loadLibRequest = {
url: 'http://kjur.github.io/jsrsasign/jsrsasign-latest-all-min.js',
method: 'GET',
header: {
'Accept': '*/*'
}
pm.sendRequest(loadLibRequest,(error, response) => {
pm.globals.set("jsrsasign-js",response.body);});
};
eval(pm.globals.get("jsrsasign-js"));
var sJWS = KJUR.jws.JWS.sign('RS256',sheader,sig,privateKey);
let me know if you have any issues.