Configure authorization in Node.js SOAP Client

I want to access the WSDL service through the SOAP client in Node.js. I used the node soap module. But I can not find the documentation for setting the username and password. I'm not going to create a SOAP server, I just want the SOAPClient to be like PHP SoapClient, using which I could access the WSDL service.

Update

I used forked and configured the source to support this function https://github.com/sincerekamal/node-soap

+8
soap web-services
source share
6 answers

You can specify a username and password as follows:

var soap = require('soap'); var url = 'your WSDL url'; var auth = "Basic " + new Buffer("your username" + ":" + "your password").toString("base64"); soap.createClient(url, { wsdl_headers: {Authorization: auth} }, function(err, client) { }); 

(obtained from https://github.com/vpulim/node-soap/issues/56 , thanks to Gabriel Lucena https://github.com/glucena )

+20
source share

Another option to add basic authentication is to use client.addHttpHeader. I tried both setSecurity and wsdl_headers setup, but it didn’t work for me when authenticating with Cisco CUCM AXL.

Here is what worked for me:

 var soap = require('soap'); var url = 'AXLAPI.wsdl'; // Download this file and xsd files from cucm admin page var auth = "Basic " + new Buffer("your username" + ":" + "your password").toString("base64"); soap.createClient(url,function(err,client){ client.addHttpHeader('Authorization',auth); }); 
+7
source share

Just to share what I read from https://github.com/vpulim/node-soap :

 var soap = require('soap'); var url = 'your WSDL url'; soap.createClient(url, function(err, client) { client.setSecurity(new soap.BasicAuthSecurity('your username','your password')); }); 
+6
source share

You need to specify a username and password, passing authorization to the wsdl_headers object, for example,

 var auth = "Basic " + new Buffer('username' + ':' + 'password').toString("base64"); var client = Soap.createClient('wsdlUrl', { wsdl_headers: { Authorization: auth } }, (err, client) => { if (err) { throw err; } else { client.yourMethod(); } }); 
+3
source share

A small tweak to existing answers: you can use your security object to create a header and to request a WSDL, for example:

 const security = new soap.BasicAuthSecurity(username, password); const wsdl_headers = {}; security.addHeaders(wsdl_headers); soap.createClientAsync(url, { wsdl_headers }).then((err, client) => { client.setSecurity(security); // etc. }); 

Or, if you are using something more complex than BasicAuthSecurity, you might also need to set wsdl_options from a security object, for example

 const security = new soap.NTLMSecurity(username, password, domain, workstation); const wsdl_headers = {}, wsdl_options = {}; security.addHeaders(wsdl_headers); security.addOptions(wsdl_options); soap.createClientAsync(url, { wsdl_headers, wsdl_options }).then((err, client) => { client.setSecurity(security); // etc. }); 
+2
source share
  I am getting this error: Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate altnames Here my code: var soap = require('soap'); var url = 'your WSDL url'; var auth = "Basic " + new Buffer("your username" + ":" + "your password").toString("base64"); soap.createClient(url, { wsdl_headers: {Authorization: auth} }, function(err, client) { client.setSecurity(new soap.BasicAuthSecurity('your username','your password')); client.yourfunction(args, function (err, result) { if (err) { console.log('Error: ', err); } else { console.log('Result: ', result); } }); 
0
source share

All Articles