Files

HTTPClient::WWWAuth

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.

Attributes

basic_auth[R]
digest_auth[R]
negotiate_auth[R]
sspi_negotiate_auth[R]

Public Class Methods

new() click to toggle source

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

Public Instance Methods

filter_request(req) click to toggle source

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_response(req, res) click to toggle source

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
reset_challenge() click to toggle source

Resets challenge state. See sub filters for more details.

    # File lib/httpclient/auth.rb, line 85
85:     def reset_challenge
86:       @authenticator.each do |auth|
87:         auth.reset_challenge
88:       end
89:     end
set_auth(uri, user, passwd) click to toggle source

Set authentication credential. See sub filters for more details.

    # File lib/httpclient/auth.rb, line 92
92:     def set_auth(uri, user, passwd)
93:       @authenticator.each do |auth|
94:         auth.set(uri, user, passwd)
95:       end
96:       reset_challenge
97:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.