class HTTPClient::DigestAuth

Authentication filter for handling DigestAuth negotiation. Used in WWWAuth.

Attributes

scheme[R]

Authentication scheme.

Public Class Methods

new() click to toggle source

Creates new DigestAuth filter.

# File lib/httpclient/auth.rb, line 338
def initialize
  super
  @auth = {}
  @challenge = {}
  @set = false
  @nonce_count = 0
  @scheme = "Digest"
end

Public Instance Methods

challenge(uri, param_str) click to toggle source

Challenge handler: remember URL and challenge token for response.

# File lib/httpclient/auth.rb, line 394
def challenge(uri, param_str)
  synchronize {
    @challenge[uri] = parse_challenge_param(param_str)
    true
  }
end
get(req) click to toggle source

Response handler: returns credential. It sends cred only when a given uri is;

  • child page of challengeable(got *Authenticate before) uri and,

  • child page of defined credential

# File lib/httpclient/auth.rb, line 378
def get(req)
  target_uri = req.header.request_uri
  synchronize {
    param = Util.hash_find_value(@challenge) { |uri, v|
      Util.uri_part_of(target_uri, uri)
    }
    return nil unless param
    user, passwd = Util.hash_find_value(@auth) { |uri, auth_data|
      Util.uri_part_of(target_uri, uri)
    }
    return nil unless user
    calc_cred(req, user, passwd, param)
  }
end
reset_challenge() click to toggle source

Resets challenge state. Do not send ‘*Authorization’ header until the server sends ‘*Authentication’ again.

# File lib/httpclient/auth.rb, line 349
def reset_challenge
  synchronize do
    @challenge.clear
  end
end
set(uri, user, passwd) click to toggle source

Set authentication credential. uri == nil is ignored.

# File lib/httpclient/auth.rb, line 357
def set(uri, user, passwd)
  synchronize do
    if uri
      uri = Util.uri_dirname(uri)
      @auth[uri] = [user, passwd]
    end
    @set = true
  end
end
set?() click to toggle source

have we marked this as set - ie that it’s valid to use in this context?

# File lib/httpclient/auth.rb, line 368
def set?
  synchronize {
    @set == true
  }
end