我将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()方法设置基本身份验证和证书时。它覆盖了我使用setSecurity()设置的第一项内容。如果我没有通过其中的任何一个,我就会收到未经授权的错误。
请帮我提供解决方案的解决方案。
发布于 2017-09-01 23:37:38
同时获得客户端证书和基本身份验证的一个好方法是使用implement your own node-soap
security protocol。您可以从existing node-soap
security protocols中获得灵感并将它们组合在一起,或者编写一个足够通用的协议来链接两个(或更多)现有的安全协议。当然,使用解决方案创建一个拉取请求会更好,因此可以考虑将其直接包含在node-soap
中。
我个人最终将带有configured https.Agent(...)
的附加options
传递给了BasicAuthSecurity
构造函数/class。
var https = require('https');
var options = {
// https://nodejs.org/api/https.html#https_class_https_agent
agent: new https.Agent({
key: someKeyBuffer,
cert: someCertBuffer,
ca: [
someCACertBuffer,
]
});
}
client.setSecurity(new soap.BasicAuthSecurity('username', 'password', options));
此方法还可用于将基本身份验证与ClientSSLSecurityPFX
中使用的.pfx
or .p12
文件相结合
https://stackoverflow.com/questions/44965044
复制相似问题