Class: HTTPClient::WWWAuth

Inherits:
AuthFilterBase show all
Defined in:
lib/httpclient.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWWWAuth

Returns a new instance of WWWAuth.



593
594
595
596
597
598
599
# File 'lib/httpclient.rb', line 593

def initialize
  @basic_auth = BasicAuth.new
  @digest_auth = DigestAuth.new
  @negotiate_auth = NegotiateAuth.new
  # sort authenticators by priority
  @authenticator = [@negotiate_auth, @digest_auth, @basic_auth]
end

Instance Attribute Details

#basic_authObject (readonly)

Returns the value of attribute basic_auth.



589
590
591
# File 'lib/httpclient.rb', line 589

def basic_auth
  @basic_auth
end

#digest_authObject (readonly)

Returns the value of attribute digest_auth.



590
591
592
# File 'lib/httpclient.rb', line 590

def digest_auth
  @digest_auth
end

#negotiate_authObject (readonly)

Returns the value of attribute negotiate_auth.



591
592
593
# File 'lib/httpclient.rb', line 591

def negotiate_auth
  @negotiate_auth
end

Instance Method Details

#filter_request(req) ⇒ Object



612
613
614
615
616
617
618
619
# File 'lib/httpclient.rb', line 612

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_response(req, res) ⇒ Object



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'lib/httpclient.rb', line 621

def filter_response(req, res)
  command = nil
  uri = req.header.request_uri
  if res.status == HTTP::Status::UNAUTHORIZED
    if challenge = parse_authentication_header(res, 'www-authenticate')
      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

#reset_challengeObject



601
602
603
604
605
# File 'lib/httpclient.rb', line 601

def reset_challenge
  @authenticator.each do |auth|
    auth.reset_challenge
  end
end

#set_auth(uri, user, passwd) ⇒ Object



607
608
609
610
# File 'lib/httpclient.rb', line 607

def set_auth(uri, user, passwd)
  @basic_auth.set(uri, user, passwd)
  @digest_auth.set(uri, user, passwd)
end