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 def initialize @basic_auth = BasicAuth.new @digest_auth = DigestAuth.new @negotiate_auth = NegotiateAuth.new @sspi_negotiate_auth = SSPINegotiateAuth.new # sort authenticators by priority @authenticator = [@negotiate_auth, @sspi_negotiate_auth, @digest_auth, @basic_auth] end
Filter API implementation. Traps HTTP request and insert 'Authorization' header if needed.
# File lib/httpclient/auth.rb, line 101 def filter_request(req) @authenticator.each do |auth| if cred = auth.get(req) req.header.set('Authorization', auth.scheme + " " + cred) return end end end
Filter API implementation. Traps HTTP response and parses 'WWW-Authenticate' header.
# File lib/httpclient/auth.rb, line 112 def filter_response(req, res) command = nil if res.status == HTTP::Status::UNAUTHORIZED if challenge = parse_authentication_header(res, 'www-authenticate') uri = req.header.request_uri challenge.each do |scheme, param_str| @authenticator.each do |auth| if scheme.downcase == auth.scheme.downcase challengeable = auth.challenge(uri, param_str) command = :retry if challengeable end end end # ignore unknown authentication scheme end end command end
Generated with the Darkfish Rdoc Generator 2.