Sha256: 5d6834f65011f0aa811a6d9fc146d7d49a618d29e21e008bb8a99bf3c956c324

Contents?: true

Size: 862 Bytes

Versions: 27

Compression:

Stored size: 862 Bytes

Contents

# frozen_string_literal: true

require "base64"
require "ntlm"

module HTTPX
  module Plugins
    module Authentication
      class Ntlm
        using RegexpExtensions unless Regexp.method_defined?(:match?)

        def initialize(user, password, domain: nil)
          @user = user
          @password = password
          @domain = domain
        end

        def can_authenticate?(authenticate)
          authenticate && /NTLM .*/.match?(authenticate)
        end

        def negotiate
          "NTLM #{NTLM.negotiate(domain: @domain).to_base64}"
        end

        def authenticate(_req, www)
          challenge = www[/NTLM (.*)/, 1]

          challenge = Base64.decode64(challenge)
          ntlm_challenge = NTLM.authenticate(challenge, @user, @domain, @password).to_base64

          "NTLM #{ntlm_challenge}"
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
httpx-0.24.7 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.24.6 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.24.5 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.24.4 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.24.3 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.24.2 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.24.1 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.24.0 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.23.4 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.23.3 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.23.2 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.23.1 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.23.0 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.22.5 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.22.4 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.22.3 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.22.2 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.22.1 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.22.0 lib/httpx/plugins/authentication/ntlm.rb
httpx-0.21.1 lib/httpx/plugins/authentication/ntlm.rb