Authentication filter for handling authentication negotiation between Web server. Parses ‘WWW-Authentication’ header in response and generates ‘Authorization’ header in request.
Authentication filter is implemented using request filter of HTTPClient. It traps HTTP response header and maintains authentication state, and traps HTTP request header for inserting necessary authentication header.
WWWAuth has sub filters (BasicAuth, DigestAuth, NegotiateAuth and SSPINegotiateAuth) and delegates some operations to it. NegotiateAuth requires ‘ruby/ntlm’ module. SSPINegotiateAuth requires ‘win32/sspi’ module.
Creates new WWWAuth.
# File lib/httpclient/auth.rb, line 75 75: def initialize 76: @basic_auth = BasicAuth.new 77: @digest_auth = DigestAuth.new 78: @negotiate_auth = NegotiateAuth.new 79: @sspi_negotiate_auth = SSPINegotiateAuth.new 80: # sort authenticators by priority 81: @authenticator = [@negotiate_auth, @sspi_negotiate_auth, @digest_auth, @basic_auth] 82: end
Filter API implementation. Traps HTTP request and insert ‘Authorization’ header if needed.
# File lib/httpclient/auth.rb, line 101 101: def filter_request(req) 102: @authenticator.each do |auth| 103: if cred = auth.get(req) 104: req.header.set('Authorization', auth.scheme + " " + cred) 105: return 106: end 107: end 108: end
Filter API implementation. Traps HTTP response and parses ‘WWW-Authenticate’ header.
# File lib/httpclient/auth.rb, line 112 112: def filter_response(req, res) 113: command = nil 114: if res.status == HTTP::Status::UNAUTHORIZED 115: if challenge = parse_authentication_header(res, 'www-authenticate') 116: uri = req.header.request_uri 117: challenge.each do |scheme, param_str| 118: @authenticator.each do |auth| 119: if scheme.downcase == auth.scheme.downcase 120: challengeable = auth.challenge(uri, param_str) 121: command = :retry if challengeable 122: end 123: end 124: end 125: # ignore unknown authentication scheme 126: end 127: end 128: command 129: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.