Module: Net::HTTPHeader

### Home Classes Methods

### In Files

- lib/httparty/net_digest_auth.rb

### Methods

- #digest_auth

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- HTTParty
- HTTParty::AllowedFormatsDeprecation
- HTTParty::ClassMethods
- HTTParty::Parser
- HTTParty::RedirectionTooDeep
- HTTParty::Response
- HTTParty::Response::Headers
- HTTParty::ResponseError
- HTTParty::UnsupportedFormat
- HTTParty::UnsupportedURIScheme
- Net
- Net::HTTPHeader

No matching classes.

# Net::HTTPHeader

### Public Instance Methods

digest_auth(user, password, response) click to toggle source

    # File lib/httparty/net_digest_auth.rb, line 6
    def digest_auth(user, password, response)
      response['www-authenticate'] =~ /^(\w+) (.*)/

      params = {}
      $2.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }
      params.merge!("cnonce" => Digest::MD5.hexdigest("%x" % (Time.now.to_i + rand(65535))))

      a_1 = Digest::MD5.hexdigest("#{user}:#{params['realm']}:#{password}")
      a_2 = Digest::MD5.hexdigest("#{@method}:#{@path}")

      request_digest = Digest::MD5.hexdigest(
        [a_1, params['nonce'], "0", params['cnonce'], params['qop'], a_2].join(":")
      )

      header = [
        %(Digest username="#{user}"),
        %(realm="#{params['realm']}"),
        %(qop="#{params['qop']}"),
        %(uri="#{@path}"),
        %(nonce="#{params['nonce']}"),
        %(nc="0"),
        %(cnonce="#{params['cnonce']}"),
        %(opaque="#{params['opaque']}"),
        %(response="#{request_digest}")
      ]

      @header['Authorization'] = header
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.