Class: FinAppsCore::Middleware::NoEncodingBasicAuthentication
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- FinAppsCore::Middleware::NoEncodingBasicAuthentication
- 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
- #call(env) ⇒ Object
-
#initialize(app, token) ⇒ NoEncodingBasicAuthentication
constructor
A new instance of NoEncodingBasicAuthentication.
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 |