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.



673
674
675
676
677
678
679
# File 'lib/httpclient.rb', line 673

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.



669
670
671
# File 'lib/httpclient.rb', line 669

def basic_auth
  @basic_auth
end

#digest_authObject (readonly)

Returns the value of attribute digest_auth.



670
671
672
# File 'lib/httpclient.rb', line 670

def digest_auth
  @digest_auth
end

#negotiate_authObject (readonly)

Returns the value of attribute negotiate_auth.



671
672
673
# File 'lib/httpclient.rb', line 671

def negotiate_auth
  @negotiate_auth
end

Instance Method Details

#filter_request(req) ⇒ Object



693
694
695
696
697
698
699
700
# File 'lib/httpclient.rb', line 693

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



702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
# File 'lib/httpclient.rb', line 702

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



681
682
683
684
685
# File 'lib/httpclient.rb', line 681

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

#set_auth(uri, user, passwd) ⇒ Object



687
688
689
690
691
# File 'lib/httpclient.rb', line 687

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