Class: FinAppsCore::Middleware::NoEncodingBasicAuthentication

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb

Overview

Adds a custom header for basic authorization. If the value for this header already exists, it is not overriden.

Constant Summary collapse

KEY =
'Authorization'

Instance Method Summary collapse

Constructor Details

#initialize(app, token) ⇒ NoEncodingBasicAuthentication

Returns a new instance of NoEncodingBasicAuthentication.



10
11
12
13
14
# File 'lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb', line 10

def initialize(app, token)
  super(app)
  sanitized = token.to_s.strip.delete("\n")
  @header_value = "Bearer #{sanitized}"
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
# File 'lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb', line 16

def call(env)
  env[:request_headers][KEY] ||= @header_value
  @app.call(env)
end