title: node-soap - How to pass certificates and basic Authorization header with every request?
body: <p>I am using <a href="https://github.com/vpulim/node-soap" rel="nofollow noreferrer">node-soap</a> 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.</p>
  
  <p>I have implemented my code as follow : </p>
  
  <pre><code>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 ::: &gt;",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 :::: &gt;&gt;&gt;&gt;&gt; ",client.lastRequest);
              if(err){
                  console.log("ERROR Enrichment :::: &gt;&gt;&gt; ", err);
              }
  
              if(result){
                  console.log("RESULT ::: &gt;&gt;&gt;&gt;", result);
              }
          })
      }
  });
  </code></pre>
  
  <p>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.</p>
  
  <p>Please help me with providing the solution the solution. </p>