Class: HTTPClient::DigestAuth

Inherits:
Object
  • Object
show all
Includes:
Mutex_m
Defined in:
lib/httpclient/auth.rb

Overview

Authentication filter for handling DigestAuth negotiation. Used in WWWAuth.

Direct Known Subclasses

ProxyDigestAuth

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDigestAuth

Creates new DigestAuth filter.



318
319
320
321
322
323
324
# File 'lib/httpclient/auth.rb', line 318

def initialize
  super
  @auth = {}
  @challenge = {}
  @nonce_count = 0
  @scheme = "Digest"
end

Instance Attribute Details

#schemeObject (readonly)

Authentication scheme.



315
316
317
# File 'lib/httpclient/auth.rb', line 315

def scheme
  @scheme
end

Instance Method Details

#challenge(uri, param_str) ⇒ Object

Challenge handler: remember URL and challenge token for response.



370
371
372
373
374
375
# File 'lib/httpclient/auth.rb', line 370

def challenge(uri, param_str)
  synchronize {
    @challenge[uri] = parse_challenge_param(param_str)
    true
  }
end

#get(req) ⇒ Object

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



354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/httpclient/auth.rb', line 354

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_challengeObject

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



328
329
330
331
332
# File 'lib/httpclient/auth.rb', line 328

def reset_challenge
  synchronize do
    @challenge.clear
  end
end

#set(uri, user, passwd) ⇒ Object

Set authentication credential. uri == nil is ignored.



336
337
338
339
340
341
342
343
# File 'lib/httpclient/auth.rb', line 336

def set(uri, user, passwd)
  synchronize do
    if uri
      uri = Util.uri_dirname(uri)
      @auth[uri] = [user, passwd]
    end
  end
end

#set?Boolean

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

Returns:

  • (Boolean)


346
347
348
# File 'lib/httpclient/auth.rb', line 346

def set?
  @auth.any?
end