Class: Userbin::Request::Middleware::BasicAuth

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

Overview

Sets credentials dynamically, allowing them to change between requests.

Instance Method Summary collapse

Constructor Details

#initialize(app, api_secret) ⇒ BasicAuth


31
32
33
34
# File 'lib/userbin/request.rb', line 31

def initialize(app, api_secret)
  super(app)
  @api_secret = api_secret
end

Instance Method Details

#call(env) ⇒ Object


36
37
38
39
40
41
# File 'lib/userbin/request.rb', line 36

def call(env)
  value = Base64.encode64(":#{@api_secret || Userbin.config.api_secret}")
  value.delete!("\n")
  env[:request_headers]["Authorization"] = "Basic #{value}"
  @app.call(env)
end