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.



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

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



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

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?
    header << %(cnonce="#{@cnonce}")
    header << %(qop="#{@response['qop']}")
    header << 'nc=00000001'
  end

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


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

def cookie_header
  @cookies
end