Class: Net::HTTPHeader::DigestAuthenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/httparty/net_digest_auth.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, password, method, path, response_header) ⇒ DigestAuthenticator

Returns a new instance of DigestAuthenticator.



25
26
27
28
29
30
31
32
# File 'lib/httparty/net_digest_auth.rb', line 25

def initialize(username, password, method, path, response_header)
  @username = username
  @password = password
  @method   = method
  @path     = path
  @response = parse(response_header)
  @cookies  = parse_cookies(response_header)
end

Instance Method Details

#authorization_headerObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/httparty/net_digest_auth.rb', line 34

def authorization_header
  @cnonce = md5(random)
  header = [
    %(Digest username="#{@username}"),
    %(realm="#{@response['realm']}"),
    %(nonce="#{@response['nonce']}"),
    %(uri="#{@path}"),
    %(response="#{request_digest}")
  ]

  header << %(algorithm="#{@response['algorithm']}") if algorithm_present?

  if qop_present?
    fields = [
      %(cnonce="#{@cnonce}"),
      %(qop="#{@response['qop']}"),
      "nc=00000001"
    ]
    fields.each { |field| header << field }
  end

  header << %(opaque="#{@response['opaque']}") if opaque_present?
  header
end


59
60
61
# File 'lib/httparty/net_digest_auth.rb', line 59

def cookie_header
  @cookies
end