lula / ngx-soap

Simple SOAP client for Angular
MIT License
66 stars 61 forks source link

Example or feature about authentication? #27

Closed teerasej closed 6 years ago

teerasej commented 6 years ago

First of all, Thank you very much for creating this module. It's super simple to work with WSDL Web service with your module.

But as I see, we have an example for communicating with WSDL operation (with POSTing value). But what if the web service need authentication?

I just have a simple dived into node-soap's client security method. But it doesn't have a good explanation.

Did you found out how to do authentication via ngx-soap? or do you have example? or could we work this out?

lula commented 6 years ago

Hello @teerasej! You should check the security section of node-soap docs.

In ngx-soap:

import { security } from 'ngx-soap';
...
this.soap.createClient('assets/c4c-query-accounts.wsdl')
      .then(client => {
        client.setSecurity(new security.BasicAuthSecurity('user', 'pass'))
        this.client = client;
        ....

For basic auth, for instance, you can also just use headers:

this.soap.createClient('assets/your.wsdl')
      .then(client => {
        client.addHttpHeader('Authorization', 'Basic ' + btoa('user:pass'));
        this.client = client;
        ....
})

Hope that helps. Cheers!!!