Class: FaradayMiddleware::Auth
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- FaradayMiddleware::Auth
- Defined in:
- lib/appbaseio/auth_middleware.rb
Overview
Request middleware that encodes the body as JSON.
Processes only requests with matching Content-type or those without a type. If a request doesn’t have a type but has a body, it sets the Content-type to JSON MIME-type.
Doesn’t try to encode bodies that already are in string form.
Constant Summary collapse
- AUTH_HEADER =
'Authorization'.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, token = nil, options = {}) ⇒ Auth
constructor
A new instance of Auth.
Constructor Details
#initialize(app, token = nil, options = {}) ⇒ Auth
Returns a new instance of Auth.
12 13 14 15 16 17 18 |
# File 'lib/appbaseio/auth_middleware.rb', line 12 def initialize(app, token = nil, = {}) super(app) , token = token, nil if token.is_a? Hash @token = token && token.to_s @auth_header = .fetch(:auth_header, AUTH_HEADER).to_s raise ArgumentError, ":auth_header can't be blank" if @auth_header.empty? end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 |
# File 'lib/appbaseio/auth_middleware.rb', line 20 def call(env) env[:request_headers][@auth_header] ||= @token @app.call env end |