Class: Faraday::NTLMAuth::Middleware
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::NTLMAuth::Middleware
- Defined in:
- lib/faraday/ntlm_auth/middleware.rb
Overview
This class provides the main implementation for your middleware. Your middleware can implement any of the following methods:
-
on_request - called when the request is being prepared
-
on_complete - called when the response is being processed
Optionally, you can also override the following methods from Faraday::Middleware
-
initialize(app, options = {}) - the initializer method
-
call(env) - the main middleware invocation method. This already calls on_request and on_complete, so you normally don’t need to override it. You may need to in case you need to “wrap” the request or need more control (see “retry” middleware: github.com/lostisland/faraday-retry/blob/41b7ea27e30d99ebfed958abfa11d12b01f6b6d1/lib/faraday/retry/middleware.rb#L147). IMPORTANT: Remember to call ‘@app.call(env)` or `super` to not interrupt the middleware chain!
Instance Method Summary collapse
-
#on_request(env) ⇒ Object
This method will be called when the request is being prepared.
Instance Method Details
#on_request(env) ⇒ Object
This method will be called when the request is being prepared. You can alter it as you like, accessing things like request_body, request_headers, and more. Refer to Faraday::Env for a list of accessible fields: github.com/lostisland/faraday/blob/main/lib/faraday/options/env.rb
26 27 28 29 30 31 32 33 34 |
# File 'lib/faraday/ntlm_auth/middleware.rb', line 26 def on_request(env) = Net::NTLM::Message env[:request_headers]['Authorization'] = 'NTLM ' + ::Type1.new.encode64 response = @app.call(env.dup) challenge = response.env[:response_headers]['www-authenticate'][/(?:NTLM|Negotiate) (.*)$/, 1] = ::Type2.decode64(challenge) ntlm_auth = .response([:user, :password, :domain].zip(@options[:auth]).to_h) env[:request_headers]['Authorization'] = "NTLM #{ntlm_auth.encode64}" end |