# SOAP and NTLM Authentication

**URL:** <https://rubytalk.org/t/soap-and-ntlm-authentication/52523>\
**Category:** ruby-talk\
**Created:** [26 March 2009 22:50 UTC](https://rubytalk.org/t/soap-and-ntlm-authentication/52523 "2009-03-26T22:50:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Porter1](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@Andrew\_Porter1](https://rubytalk.org/u/Andrew_Porter1)\
**Post date:** [26 March 2009 22:50 UTC](https://rubytalk.org/t/soap-and-ntlm-authentication/52523/1 "2009-03-26T22:50:12Z")

</div>

I'm trying to integrate with Sharepoint Services, and need to connect to the server using NTLM authentication. I can't get the following lines of code to work:

WSDL\_URL = '[http://sharepoint.wavetronix.local/\_vti\_bin/lists.asmx?WSDL](http://sharepoint.wavetronix.local/_vti_bin/lists.asmx?WSDL)'  
soap = SOAP::WSDLDriverFactory.new(WSDL\_URL).create\_rpc\_driver

I keep getting a 401, "Unauthorized" error. This code does work:

client = HTTPClient.new  
client.set\_auth(nil, 'DOMAIN\username', 'password')  
response = client.get(WSDL\_URL)

All examples I find show setting authorization properties AFTER the create\_rpc\_driver call above. I need to authorize BEFORE so I can actually access the WSDL file. How do I do this?

Andy Porter  
p: (801) 319-0475 | e: [partydrone@me.com](mailto:partydrone@me.com)

---

<div class="post-metadata">

**Author:** ![Mark\_Thomas](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@Mark\_Thomas](https://rubytalk.org/u/Mark_Thomas)\
**Post date:** [27 March 2009 09:16 UTC](https://rubytalk.org/t/soap-and-ntlm-authentication/52523/2 "2009-03-27T09:16:43Z")

</div>

[http://markthomas.org/2007/09/12/getting-started-with-soap4r/](http://markthomas.org/2007/09/12/getting-started-with-soap4r/)

> **···**
>
> On Mar 26, 6:50 pm, Andrew Porter \<partydr...@me.com\> wrote:
> 
> > [Note: parts of this message were removed to make it a legal post.]
> > 
> > I'm trying to integrate with Sharepoint Services, and need to connect  
> > to the server using NTLM authentication. I can't get the following  
> > lines of code to work:
> > 
> > WSDL\_URL = '[http://sharepoint.wavetronix.local/\_vti\_bin/lists.asmx?WSDL&#39](http://sharepoint.wavetronix.local/_vti_bin/lists.asmx?WSDL&#39);  
> > soap = SOAP::WSDLDriverFactory.new(WSDL\_URL).create\_rpc\_driver
> > 
> > I keep getting a 401, "Unauthorized" error. This code does work:
> > 
> > client = HTTPClient.new  
> > client.set\_auth(nil, 'DOMAIN\username', 'password')  
> > response = client.get(WSDL\_URL)
> > 
> > All examples I find show setting authorization properties AFTER the  
> > create\_rpc\_driver call above. I need to authorize BEFORE so I can  
> > actually access the WSDL file. How do I do this?

---

<div class="post-metadata">

**Author:** ![Andrew\_Porter1](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@Andrew\_Porter1](https://rubytalk.org/u/Andrew_Porter1)\
**Post date:** [27 March 2009 16:01 UTC](https://rubytalk.org/t/soap-and-ntlm-authentication/52523/3 "2009-03-27T16:01:15Z")

</div>

The example you give on your blog, like all the others I've seen, assumes the WSDL file is "in the open." In my case, I have to authenticate in order to even get to it. Your example creates the driver first, then adds authentication for subsequent requests. I can't even create the driver. The SOAP::WSDLDriverFactory.new() call fails every time with a 401, "Unauthorized" error.

Also, I'm using the SOAP libraries in Ruby 1.8.6. It's my understanding that soap4r was integrated into this version of Ruby. Am I mistaken?

> **···**
>
> On Mar 27, 2009, at 3:16 AM, Mark Thomas wrote:
> 
> > On Mar 26, 6:50 pm, Andrew Porter \<partydr...@me.com\> wrote:
> > 
> > > [Note: parts of this message were removed to make it a legal post.]
> > > 
> > > I'm trying to integrate with Sharepoint Services, and need to connect  
> > > to the server using NTLM authentication. I can't get the following  
> > > lines of code to work:
> > > 
> > > WSDL\_URL = '[http://sharepoint.wavetronix.local/\_vti\_bin/lists.asmx?WSDL&#39](http://sharepoint.wavetronix.local/_vti_bin/lists.asmx?WSDL&#39);  
> > > soap = SOAP::WSDLDriverFactory.new(WSDL\_URL).create\_rpc\_driver
> > > 
> > > I keep getting a 401, "Unauthorized" error. This code does work:
> > > 
> > > client = HTTPClient.new  
> > > client.set\_auth(nil, 'DOMAIN\username', 'password')  
> > > response = client.get(WSDL\_URL)
> > > 
> > > All examples I find show setting authorization properties AFTER the  
> > > create\_rpc\_driver call above. I need to authorize BEFORE so I can  
> > > actually access the WSDL file. How do I do this?
> > 
> > [markthomas.org](http://markthomas.org/2007/09/12/getting-started-with-soap4r/)

---

<div class="post-metadata">

**Author:** ![Dan\_Webb](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@Dan\_Webb](https://rubytalk.org/u/Dan_Webb)\
**Post date:** [27 March 2009 16:10 UTC](https://rubytalk.org/t/soap-and-ntlm-authentication/52523/4 "2009-03-27T16:10:41Z")

</div>

I'm not sure it'll be totally helpful. But the tutorial I wrote on  
adding extra header using SOAP4R may point you in the right direction.

[http://dan-webb.co.uk/wordpress/?p=13](http://dan-webb.co.uk/wordpress/?p=13)

SOAP4R was integrated in 1.8.6 but is an old and buggy version of it. So  
you Hiro recommends you update it and use the newer version (1.5.8)

Cheers,  
Dan

> **···**
>
> -----Original Message-----  
> From: Andrew Porter [mailto:partydrone@me.com]  
> Sent: 27 March 2009 16:01  
> To: ruby-talk ML  
> Subject: Re: SOAP and NTLM Authentication
> 
> The example you give on your blog, like all the others I've seen,  
> assumes the WSDL file is "in the open." In my case, I have to  
> authenticate in order to even get to it. Your example creates the  
> driver first, then adds authentication for subsequent requests. I  
> can't even create the driver. The SOAP::WSDLDriverFactory.new() call  
> fails every time with a 401, "Unauthorized" error.
> 
> Also, I'm using the SOAP libraries in Ruby 1.8.6. It's my  
> understanding that soap4r was integrated into this version of Ruby. Am  
> I mistaken?
> 
> On Mar 27, 2009, at 3:16 AM, Mark Thomas wrote:
> 
> > On Mar 26, 6:50 pm, Andrew Porter \<partydr...@me.com\> wrote:
> > 
> > > [Note: parts of this message were removed to make it a legal post.]
> > > 
> > > I'm trying to integrate with Sharepoint Services, and need to connect  
> > > to the server using NTLM authentication. I can't get the following  
> > > lines of code to work:
> > > 
> > > WSDL\_URL =
> 
> '[http://sharepoint.wavetronix.local/\_vti\_bin/lists.asmx?WSDL&#39](http://sharepoint.wavetronix.local/_vti_bin/lists.asmx?WSDL&#39);
> 
> > > soap = SOAP::WSDLDriverFactory.new(WSDL\_URL).create\_rpc\_driver
> > > 
> > > I keep getting a 401, "Unauthorized" error. This code does work:
> > > 
> > > client = HTTPClient.new  
> > > client.set\_auth(nil, 'DOMAIN\username', 'password')  
> > > response = client.get(WSDL\_URL)
> > > 
> > > All examples I find show setting authorization properties AFTER the  
> > > create\_rpc\_driver call above. I need to authorize BEFORE so I can  
> > > actually access the WSDL file. How do I do this?
> > 
> > [markthomas.org](http://markthomas.org/2007/09/12/getting-started-with-soap4r/)

---

<div class="post-metadata">

**Author:** ![Mark\_Thomas](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@Mark\_Thomas](https://rubytalk.org/u/Mark_Thomas)\
**Post date:** [27 March 2009 17:27 UTC](https://rubytalk.org/t/soap-and-ntlm-authentication/52523/5 "2009-03-27T17:27:07Z")

</div>

> The example you give on your blog, like all the others I've seen,  
> assumes the WSDL file is "in the open." In my case, I have to  
> authenticate in order to even get to it. Your example creates the  
> driver first, then adds authentication for subsequent requests. I  
> can't even create the driver. The SOAP::WSDLDriverFactory.new() call  
> fails every time with a 401, "Unauthorized" error.

Since you have shown you can get the WSDL, can't you just use it  
locally when generating your client?

wsdl2ruby --wsdl \<local\_filename.wsdl\> --type client --force

> Also, I'm using the SOAP libraries in Ruby 1.8.6. It's my  
> understanding that soap4r was integrated into this version of Ruby. Am  
> I mistaken?

Do NOT use the built-in libraries. Please upgrade to the latest.

> **···**
>
> On Mar 27, 12:01 pm, Andrew Porter \<partydr...@me.com\> wrote:

---

<div class="post-metadata">

**Author:** ![Andrew\_Porter1](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@Andrew\_Porter1](https://rubytalk.org/u/Andrew_Porter1)\
**Post date:** [27 March 2009 17:52 UTC](https://rubytalk.org/t/soap-and-ntlm-authentication/52523/6 "2009-03-27T17:52:23Z")

</div>

The following code seems to be working:

require 'rubygems'  
gem 'soap4r'  
require 'defaultDriver'

user = 'DOMAIN\username'  
pass = 'password'

driver = ListsSoap.new  
driver.options['protocol.http.auth.ntlm'] = [nil, user, pass]  
driver.wiredump\_file\_base = 'soap.log'

lists = driver.getListCollection(nil)

I used the wsdl2ruby utility and generated the files. I was, however,  
hoping to do this dynamically…

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Vetrivel\_Vaithilinga](https://avatars.discourse-cdn.com/v4/letter/v/958977/32.png) [@Vetrivel\_Vaithilinga](https://rubytalk.org/u/Vetrivel_Vaithilinga)\
**Post date:** [26 May 2010 14:57 UTC](https://rubytalk.org/t/soap-and-ntlm-authentication/52523/7 "2010-05-26T14:57:06Z")

</div>

Andrew Porter wrote:

> The following code seems to be working:
> 
> require 'rubygems'  
> gem 'soap4r'  
> require 'defaultDriver'
> 
> user = 'DOMAIN\username'  
> pass = 'password'
> 
> driver = ListsSoap.new  
> driver.options['protocol.http.auth.ntlm'] = [nil, user, pass]  
> driver.wiredump\_file\_base = 'soap.log'
> 
> lists = driver.getListCollection(nil)
> 
> I used the wsdl2ruby utility and generated the files. I was, however,  
> hoping to do this dynamically…

Hai ,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I have tried this . But it is not working . For network  
credential i have used this . After using also , i got Authentication  
failure error from the server .

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
