Class: HTTPClient::DigestAuth
- Inherits:
-
Object
- Object
- HTTPClient::DigestAuth
- Defined in:
- lib/httpclient/auth.rb
Overview
Authentication filter for handling DigestAuth negotiation. Used in WWWAuth.
Instance Attribute Summary collapse
-
#scheme ⇒ Object
readonly
Authentication scheme.
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.
-
#reset_challenge ⇒ Object
Resets challenge state.
-
#set(uri, user, passwd) ⇒ Object
Set authentication credential.
Constructor Details
#initialize ⇒ DigestAuth
Creates new DigestAuth filter.
274 275 276 277 278 279 |
# File 'lib/httpclient/auth.rb', line 274 def initialize @auth = {} @challenge = {} @nonce_count = 0 @scheme = "Digest" end |
Instance Attribute Details
#scheme ⇒ Object (readonly)
Authentication scheme.
271 272 273 |
# File 'lib/httpclient/auth.rb', line 271 def scheme @scheme end |
Instance Method Details
#challenge(uri, param_str) ⇒ Object
Challenge handler: remember URL and challenge token for response.
314 315 316 317 |
# File 'lib/httpclient/auth.rb', line 314 def challenge(uri, param_str) @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
300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/httpclient/auth.rb', line 300 def get(req) target_uri = req.header.request_uri 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 ⇒ Object
Resets challenge state. Do not send ‘*Authorization’ header until the server sends ‘*Authentication’ again.
283 284 285 |
# File 'lib/httpclient/auth.rb', line 283 def reset_challenge @challenge.clear end |
#set(uri, user, passwd) ⇒ Object
Set authentication credential. uri == nil is ignored.
289 290 291 292 293 294 |
# File 'lib/httpclient/auth.rb', line 289 def set(uri, user, passwd) if uri uri = Util.uri_dirname(uri) @auth[uri] = [user, passwd] end end |