Class: Request::BasicAuth

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/faraday/request/basic_auth.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options) ⇒ BasicAuth

Returns a new instance of BasicAuth.



13
14
15
# File 'lib/faraday/request/basic_auth.rb', line 13

def initialize(app, options)
  @app, @options = app, options
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
# File 'lib/faraday/request/basic_auth.rb', line 7

def call(env)
  header = Base64.encode64("#{@options[:username]}:#{@options[:password]}")
  env[:request_headers]['Authorization'] = "Basic #{header.to_s}"
  @app.call(env)
end