首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >node-soap -如何为每个请求传递证书和基本Authorization头?

node-soap -如何为每个请求传递证书和基本Authorization头?
EN

Stack Overflow用户
提问于 2017-07-07 15:32:04
回答 1查看 2.7K关注 0票数 2

我将node-soap lib用于SOAP服务,这是我第一次使用它。我有一个要求,我需要通过证书和每个强制性的基本授权头。

我将我的代码实现如下:

代码语言:javascript
运行
复制
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()设置的第一项内容。如果我没有通过其中的任何一个,我就会收到未经授权的错误。

请帮我提供解决方案的解决方案。

EN

回答 1

Stack Overflow用户

发布于 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

代码语言:javascript
运行
复制
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文件相结合

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44965044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档