Object
Authentication filter for handling Negotiate/NTLM negotiation. Used in WWWAuth and ProxyAuth.
NegotiateAuth depends on ‘ruby/ntlm’ module.
Creates new NegotiateAuth filter.
# File lib/httpclient/auth.rb, line 379
379: def initialize
380: @auth = {}
381: @auth_default = nil
382: @challenge = {}
383: @scheme = "Negotiate"
384: @ntlm_opt = {
385: :ntlmv2 => true
386: }
387: end
Challenge handler: remember URL and challenge token for response.
# File lib/httpclient/auth.rb, line 438
438: def challenge(uri, param_str)
439: return false unless NTLMEnabled
440: if param_str.nil? or @challenge[uri].nil?
441: c = @challenge[uri] = {}
442: c[:state] = :init
443: c[:authphrase] = ""
444: else
445: c = @challenge[uri]
446: c[:state] = :response
447: c[:authphrase] = param_str
448: end
449: true
450: end
Response handler: returns credential. See ruby/ntlm for negotiation state transition.
# File lib/httpclient/auth.rb, line 408
408: def get(req)
409: return nil unless NTLMEnabled
410: target_uri = req.header.request_uri
411: domain_uri, param = @challenge.find { |uri, v|
412: Util.uri_part_of(target_uri, uri)
413: }
414: return nil unless param
415: user, passwd = Util.hash_find_value(@auth) { |uri, auth_data|
416: Util.uri_part_of(target_uri, uri)
417: }
418: unless user
419: user, passwd = @auth_default
420: end
421: return nil unless user
422: state = param[:state]
423: authphrase = param[:authphrase]
424: case state
425: when :init
426: t1 = Net::NTLM::Message::Type1.new
427: return t1.encode64
428: when :response
429: t2 = Net::NTLM::Message.decode64(authphrase)
430: t3 = t2.response({:user => user, :password => passwd}, @ntlm_opt.dup)
431: @challenge.delete(domain_uri)
432: return t3.encode64
433: end
434: nil
435: end
Resets challenge state. Do not send ’*Authorization’ header until the server sends ’*Authentication’ again.
# File lib/httpclient/auth.rb, line 391
391: def reset_challenge
392: @challenge.clear
393: end
Set authentication credential. uri == nil for generic purpose (allow to use user/password for any URL).
# File lib/httpclient/auth.rb, line 397
397: def set(uri, user, passwd)
398: if uri
399: uri = Util.uri_dirname(uri)
400: @auth[uri] = [user, passwd]
401: else
402: @auth_default = [user, passwd]
403: end
404: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.