class HTTPClient::BasicAuth

Authentication filter for handling BasicAuth negotiation. Used in WWWAuth and ProxyAuth.

Attributes

scheme[R]

Authentication scheme.

Public Class Methods

new() click to toggle source

Creates new BasicAuth filter.

# File lib/httpclient/auth.rb, line 237
def initialize
  @cred = nil
  @set = false
  @auth = {}
  @challengeable = {}
  @scheme = "Basic"
end

Public Instance Methods

challenge(uri, param_str = nil) click to toggle source

Challenge handler: remember URL for response.

# File lib/httpclient/auth.rb, line 284
def challenge(uri, param_str = nil)
  @challengeable[urify(uri)] = true
  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 272
def get(req)
  target_uri = req.header.request_uri
  return nil unless @challengeable.find { |uri, ok|
    Util.uri_part_of(target_uri, uri) and ok
  }
  return @cred if @cred
  Util.hash_find_value(@auth) { |uri, cred|
    Util.uri_part_of(target_uri, uri)
  }
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 247
def reset_challenge
  @challengeable.clear
end
set(uri, user, passwd) click to toggle source

Set authentication credential. uri == nil for generic purpose (allow to use user/password for any URL).

# File lib/httpclient/auth.rb, line 253
def set(uri, user, passwd)
  @set = true
  if uri.nil?
    @cred = ["#{user}:#{passwd}"].pack('m').tr("\n", '')
  else
    uri = Util.uri_dirname(uri)
    @auth[uri] = ["#{user}:#{passwd}"].pack('m').tr("\n", '')
  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 264
def set?
  @set == true
end