Class: HTTPClient::BasicAuth
- Inherits:
-
Object
- Object
- HTTPClient::BasicAuth
- Defined in:
- lib/httpclient/auth.rb
Overview
Authentication filter for handling BasicAuth negotiation. Used in WWWAuth and ProxyAuth.
Instance Attribute Summary collapse
-
#scheme ⇒ Object
readonly
Authentication scheme.
Instance Method Summary collapse
-
#challenge(uri, param_str) ⇒ Object
Challenge handler: remember URL for response.
-
#get(req) ⇒ Object
Response handler: returns credential.
-
#initialize ⇒ BasicAuth
constructor
Creates new BasicAuth filter.
-
#reset_challenge ⇒ Object
Resets challenge state.
-
#set(uri, user, passwd) ⇒ Object
Set authentication credential.
Constructor Details
#initialize ⇒ BasicAuth
Creates new BasicAuth filter.
214 215 216 217 218 219 |
# File 'lib/httpclient/auth.rb', line 214 def initialize @cred = nil @auth = {} @challengeable = {} @scheme = "Basic" end |
Instance Attribute Details
#scheme ⇒ Object (readonly)
Authentication scheme.
211 212 213 |
# File 'lib/httpclient/auth.rb', line 211 def scheme @scheme end |
Instance Method Details
#challenge(uri, param_str) ⇒ Object
Challenge handler: remember URL for response.
254 255 256 257 |
# File 'lib/httpclient/auth.rb', line 254 def challenge(uri, param_str) @challengeable[uri] = true 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
242 243 244 245 246 247 248 249 250 251 |
# File 'lib/httpclient/auth.rb', line 242 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 ⇒ Object
Resets challenge state. Do not send ‘*Authorization’ header until the server sends ‘*Authentication’ again.
223 224 225 |
# File 'lib/httpclient/auth.rb', line 223 def reset_challenge @challengeable.clear end |
#set(uri, user, passwd) ⇒ Object
Set authentication credential. uri == nil for generic purpose (allow to use user/password for any URL).
229 230 231 232 233 234 235 236 |
# File 'lib/httpclient/auth.rb', line 229 def set(uri, user, passwd) 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 |