views:

893

answers:

1

I'm trying to get a Ruby script to download a file off a server, but I'm getting a 401.2 from IIS:

You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept.

I've checked that basic auth is enabled. Is there something special about how Ruby handles basic auth? Is there a way for me to see what the server actually gets and what the headers say is acceptable?

This is my code:

   Net::HTTP.start(url, port) {|http|
      req = Net::HTTP::Get.new('/file.txt')
      req.basic_auth 'username', 'password'
      response = http.request(req)
      puts response.body
    }
+1  A: 

Snippet from the Microsoft website

HTTP 401.2: Denied by server configuration Description

The client browser and IIS could not agree on an authentication protocol.

Common reasons

* No authentication protocol (including anonymous) is selected in IIS. At least one authentication type must be selected. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
  253667  (http://support.microsoft.com/kb/253667/ ) Error message: HTTP 401.2 - Unauthorized: Logon failed due to server configuration with no authentication
* Only Integrated authentication is enabled, and an older, non-Internet Explorer client browser tries to access the site. This happens because the client browser cannot perform Integrated authentication. To resolve this problem, use one of the following methods:
      o Configure IIS to accept Basic authentication. This should only occur over SSL for security purposes.
      o Use a client browser that can perform Integrated authentication. Internet Explorer and new versions of Netscape Navigator and Mozilla Firefox can perform Integrated authentication. 
* Integrated authentication is through a proxy. This happens because the proxy doesn't maintain the NTLM-authenticated connection and thus sends an anonymous request from the client to the server. Options to resolve this problem are as follows:
      o Configure IIS to accept Basic authentication. This should only occur over SSL for security purposes.
      o Don't use a proxy.

You should also try to look at ruby-httpclient - Simple HTTPClient library for Ruby which can use NTLM auth.

Yoann Le Touche