1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
# frozen_string_literal: true
require "httpx/base64"
require "ntlm"
module HTTPX
module Plugins
module Authentication
class Ntlm
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
|