Class: HTTPX::Plugins::Authentication::Ntlm

Inherits:
Object
  • Object
show all
Defined in:
lib/httpx/plugins/auth/ntlm.rb

Instance Method Summary collapse

Constructor Details

#initialize(user, password, domain: nil) ⇒ Ntlm

Returns a new instance of Ntlm.



10
11
12
13
14
# File 'lib/httpx/plugins/auth/ntlm.rb', line 10

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

Instance Method Details

#authenticate(_req, www) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/httpx/plugins/auth/ntlm.rb', line 24

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

#can_authenticate?(authenticate) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/httpx/plugins/auth/ntlm.rb', line 16

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

#negotiateObject



20
21
22
# File 'lib/httpx/plugins/auth/ntlm.rb', line 20

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