我正在将node-soap lib 用于 SOAP 服务并首次使用它。我要求我需要在每个请求强制时都传递证书和基本授权标头。
我已经实现了我的代码如下:
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);
}
})
}
});
当我尝试使用 setSecurity() 方法设置 Basic auth 和 Certs 时。它覆盖了我使用 setSecurity() 设置的第一件事。如果我没有通过其中任何一个,我就会收到未经授权的错误。
请帮助我提供解决方案。