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.



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

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.



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

def basic_auth
  @basic_auth
end

#digest_authObject (readonly)

Returns the value of attribute digest_auth.



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

def digest_auth
  @digest_auth
end

#negotiate_authObject (readonly)

Returns the value of attribute negotiate_auth.



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

def negotiate_auth
  @negotiate_auth
end

Instance Method Details

#filter_request(req) ⇒ Object



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

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



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

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



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

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

#set_auth(uri, user, passwd) ⇒ Object



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

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