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

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Ntlm.

Parameters:

  • user (string)
  • password (string)
  • domain: (String, nil) (defaults to: nil)


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) ⇒ String

Parameters:

  • request (Request)
  • authenticate (String)

Returns:

  • (String)


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

Parameters:

  • authenticate (String, nil)

Returns:

  • (Boolean)


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

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

#negotiateString

Returns:

  • (String)


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

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