views:

422

answers:

2

I have been trying to connect to a web service that is using digest authentication.

I am able to connect in Safari using user:[email protected]/endpoint

I have tried in Ruby and Rails to connect using HTTParty and Net:HTTP using the "basic"auth" options, but have not had any luck.

Wondering if the HTTParty/Net:HTTP "basic_auth" option is not going to be compatible with a "digest auth" service?

If not, is there another way that I might connect?

A: 

HTTParty basic auth is apparently not compatible with digest_auth. I found this Net:HTTP extension: https://codesnippets.joyent.com/posts/show/1075 and am writing a method to handle this, with the help of the Crack gem http://github.com/jnunemaker/crack:

 def self.decode vin
    url = URI.parse(APP_CONFIG[:vinlink_url])
    Net::HTTP.start(url.host) do |http|
      res = http.head(url.request_uri)
      req = Net::HTTP::Get.new("/report?type=basic&vin=#{vin}")
      req.digest_auth(APP_CONFIG[:vinlink_login], APP_CONFIG[:vinlink_password], res)
      @response = http.request(req)
    end
    if @response.code == "200"
      hash = Crack::XML.parse(@response.body).recursive_downcase_keys!.recursive_symbolize_keys!
    end
  end  
Gordon Isnor
A: 

Just an update to say that Httparty is now digest_auth capable if you build it from source at github

As of now (May 2010), the version installed through gem install httparty is not yet digest-compatible. Hope this helps.

TBastiani