Class: HTTPClient::DigestAuth
- Includes:
- Mutex_m
- Defined in:
- lib/httpclient/auth.rb
Overview
Authentication filter for handling DigestAuth negotiation. Used in WWWAuth.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from AuthBase
Instance Method Summary collapse
-
#challenge(uri, param_str) ⇒ Object
Challenge handler: remember URL and challenge token for response.
-
#get(req) ⇒ Object
Response handler: returns credential.
-
#initialize ⇒ DigestAuth
constructor
Creates new DigestAuth filter.
-
#set(uri, user, passwd) ⇒ Object
Set authentication credential.
-
#set? ⇒ Boolean
have we marked this as set - ie that it’s valid to use in this context?.
Methods inherited from AuthBase
Methods included from Util
#argument_to_hash, hash_find_value, #http?, #https?, #keyword_argument, try_require, uri_dirname, uri_part_of, urify, #warning
Constructor Details
#initialize ⇒ DigestAuth
Creates new DigestAuth filter.
335 336 337 338 339 |
# File 'lib/httpclient/auth.rb', line 335 def initialize super('Digest') @auth = {} @nonce_count = 0 end |
Instance Method Details
#challenge(uri, param_str) ⇒ Object
Challenge handler: remember URL and challenge token for response.
377 378 379 380 381 382 |
# File 'lib/httpclient/auth.rb', line 377 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
361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/httpclient/auth.rb', line 361 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 |
#set(uri, user, passwd) ⇒ Object
Set authentication credential. uri == nil is ignored.
343 344 345 346 347 348 349 350 |
# File 'lib/httpclient/auth.rb', line 343 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?
353 354 355 |
# File 'lib/httpclient/auth.rb', line 353 def set? @auth.any? end |