Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node soap, consume password protected WSDL

I'm trying to build a SOAP client with Node, I'm using "soap" package (https://www.npmjs.org/package/soap) trying to consume a user/password protected WSDL.

I can't find how to pass those credentials before creating the client by "soap.createClient", and of course, I can't retrieve the WSDL if I don't provide the right credentials.

I've tried doing:

soap.security.WSSecurity('user', 'pass');

and then calling "createClient" but to no avail.

Also, I've tried to do it with the node-soap-client, with this client I (apparently) can connect to the WSDL, but after that, I've no idea where to go (how to invoke methods).

What am I doing wrong?

Thanks for all your help!

like image 822
Laerion Avatar asked Nov 19 '14 22:11

Laerion


2 Answers

Username and password credentials can be passed like this:

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) {
});

(derived from https://github.com/vpulim/node-soap/issues/56, thank you Gabriel Lucena https://github.com/glucena)

like image 163
iloo Avatar answered Sep 23 '22 12:09

iloo


If its password protected you also need to check the correct security mechanism. I spend a day trying to figure out that the service used NTLM security(it was a clients project and I only got username and password to access the wsdl). In that case, you would need to pass the correct wsdl_options object

var wsdl_options = {
  ntlm: true,
  username: "your username",
  password: "your password",
  domain: "domain",
  workstation: "workstation"
}

soap.createClient(data.credentials[data.type], {
    wsdl_options
  },
  function(err, client) {
    console.log(client.describe());
  });

Also, you would need to setSecurity on the client before using any service. the link to complete explanation: https://codecalls.com/2020/05/17/using-soap-with-node-js/

like image 28
Nitin Khare Avatar answered Sep 20 '22 12:09

Nitin Khare