Setting Authorization in Node.js SOAP Client

前端 未结 5 1075
小鲜肉
小鲜肉 2020-12-16 02:31

I want to access a WSDL service through SOAP Client in Node.js. I used soap node module. But I can\'t able to find any documentation to set username and pas

相关标签:
5条回答
  • 2020-12-16 02:54

    You can provide username and password 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)

    0 讨论(0)
  • 2020-12-16 03:03

    Just to share what I've 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'));
    });
    
    0 讨论(0)
  • 2020-12-16 03:14

    A small tweak to the existing answers: you can use your security object to create the header for the WSDL request too, e.g.

    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're using something more complicated than BasicAuthSecurity you may also need to set wsdl_options from the security object, e.g.

    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.
    });
    
    0 讨论(0)
  • 2020-12-16 03:15

    Another option to add basic authentication is using client.addHttpHeader. I tried both setSecurity and setting wsdl_headers but neither worked for me when authenticating to 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);
    });
    
    0 讨论(0)
  • 2020-12-16 03:18

    You need to set the username and password by passing the authorisation to the wsdl_headers object e.g

    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();
        }
    });
    
    0 讨论(0)
提交回复
热议问题