Sha256: 8f19b9011cba6a3330cbe464947ef4f3d5010a9e2dfeb5c78e9ea3600575df8b

Contents?: true

Size: 1.61 KB

Versions: 13

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    #
    # https://gitlab.com/os85/httpx/wikis/Auth#ntlm-auth
    #
    module NTLMAuth
      class << self
        def load_dependencies(_klass)
          require_relative "auth/ntlm"
        end

        def extra_options(options)
          options.merge(max_concurrent_requests: 1)
        end
      end

      module OptionsMethods
        def option_ntlm(value)
          raise TypeError, ":ntlm must be a #{Authentication::Ntlm}" unless value.is_a?(Authentication::Ntlm)

          value
        end
      end

      module InstanceMethods
        def ntlm_auth(user, password, domain = nil)
          with(ntlm: Authentication::Ntlm.new(user, password, domain: domain))
        end

        private

        def send_requests(*requests)
          requests.flat_map do |request|
            ntlm = request.options.ntlm

            if ntlm
              request.headers["authorization"] = ntlm.negotiate
              probe_response = wrap { super(request).first }

              return probe_response unless probe_response.is_a?(Response)

              if probe_response.status == 401 && ntlm.can_authenticate?(probe_response.headers["www-authenticate"])
                request.transition(:idle)
                request.headers["authorization"] = ntlm.authenticate(request, probe_response.headers["www-authenticate"])
                super(request)
              else
                probe_response
              end
            else
              super(request)
            end
          end
        end
      end
    end
    register_plugin :ntlm_auth, NTLMAuth
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
httpx-1.3.4 lib/httpx/plugins/ntlm_auth.rb
httpx-1.3.3 lib/httpx/plugins/ntlm_auth.rb
httpx-1.3.2 lib/httpx/plugins/ntlm_auth.rb
httpx-1.3.1 lib/httpx/plugins/ntlm_auth.rb
httpx-1.3.0 lib/httpx/plugins/ntlm_auth.rb
httpx-1.2.6 lib/httpx/plugins/ntlm_auth.rb
httpx-1.2.4 lib/httpx/plugins/ntlm_auth.rb
httpx-1.2.3 lib/httpx/plugins/ntlm_auth.rb
httpx-1.2.2 lib/httpx/plugins/ntlm_auth.rb
httpx-1.2.1 lib/httpx/plugins/ntlm_auth.rb
httpx-1.2.0 lib/httpx/plugins/ntlm_auth.rb
httpx-1.1.5 lib/httpx/plugins/ntlm_auth.rb
httpx-1.1.4 lib/httpx/plugins/ntlm_auth.rb