Class: HTTPX::Plugins::NtlmV2Auth::Authenticator
- Inherits:
-
Object
- Object
- HTTPX::Plugins::NtlmV2Auth::Authenticator
- Defined in:
- lib/httpx/plugins/ntlm_v2_auth.rb
Instance Method Summary collapse
- #authenticate(_request, www_authenticate) ⇒ Object
- #can_authenticate?(www_authenticate) ⇒ Boolean
-
#initialize(user, password, domain: nil) ⇒ Authenticator
constructor
A new instance of Authenticator.
- #negotiate ⇒ Object
Constructor Details
#initialize(user, password, domain: nil) ⇒ Authenticator
Returns a new instance of Authenticator.
19 20 21 22 23 |
# File 'lib/httpx/plugins/ntlm_v2_auth.rb', line 19 def initialize(user, password, domain: nil) @user = user @password = password @domain = domain end |
Instance Method Details
#authenticate(_request, www_authenticate) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/httpx/plugins/ntlm_v2_auth.rb', line 35 def authenticate(_request, www_authenticate) challenge_b64 = www_authenticate[/NTLM (.+)/i, 1] t2 = Net::NTLM::Message.decode64(challenge_b64) t3 = t2.response( { user: @user, password: @password, domain: @domain }, ntlmv2: true ) "NTLM #{t3.encode64}" end |
#can_authenticate?(www_authenticate) ⇒ Boolean
25 26 27 |
# File 'lib/httpx/plugins/ntlm_v2_auth.rb', line 25 def can_authenticate?(www_authenticate) www_authenticate && /NTLM/i.match?(www_authenticate) end |
#negotiate ⇒ Object
29 30 31 32 33 |
# File 'lib/httpx/plugins/ntlm_v2_auth.rb', line 29 def negotiate t1 = Net::NTLM::Message::Type1.new t1.domain = @domain if @domain "NTLM #{t1.encode64}" end |