I am using node-soap lib for SOAP services and using it for first time. I am having requirement that I need to pass both Certificates and Basic Authorization header with every request compulsory.
I have implemented my code as follow :
var options = {
wsdl_options: {
key: fs.readFileSync(path.resolve("./xxx.key")),
cert: fs.readFileSync(path.resolve("./xxx.crt")),
ca: fs.readFileSync(path.resolve("./xxx.pem")),
},
wsdl_headers : {
Authorization : 'Basic ' + new Buffer(username +':'+ password ).toString('base64')
},
"overrideRootElement": {
"namespace": "con",
},
envelopeKey : 'soapenv'
};
soap.createClient(url, options, function(err, client) {
if(err){
console.log("Error ::: >",err);
res.json({message : err});
}
if(client){
console.log(JSON.stringify(client.describe()));
var data = actualRequestObject
client.setSecurity(new soap.ClientSSLSecurity(
fs.readFileSync(path.resolve("./XXX.key")),
fs.readFileSync(path.resolve("./XXX.crt")),
fs.readFileSync(path.resolve("./XXX.pem"))
));
client.setSecurity(new soap.BasicAuthSecurity(username, password));
client.IndicativeEnrichment(data, function(err, result){
console.log("lastRequest :::: >>>>> ",client.lastRequest);
if(err){
console.log("ERROR Enrichment :::: >>> ", err);
}
if(result){
console.log("RESULT ::: >>>>", result);
}
})
}
});
When I am trying to set Basic auth and Certs both using setSecurity() method. It overrides the first thing that I've set using setSecurity(). I am getting unauthorized error if I don't pass any one of these.
Please help me with providing the solution the solution.