Class: Schwab::Middleware::Authentication

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/schwab/middleware/authentication.rb

Overview

Simple middleware for adding bearer token to requests

Instance Method Summary collapse

Constructor Details

#initialize(app, token) ⇒ Authentication

Returns a new instance of Authentication.



86
87
88
89
# File 'lib/schwab/middleware/authentication.rb', line 86

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

Instance Method Details

#call(env) ⇒ Faraday::Response

Add bearer token to the request

Parameters:

  • env (Faraday::Env)

    The request environment

Returns:

  • (Faraday::Response)

    The response



94
95
96
97
# File 'lib/schwab/middleware/authentication.rb', line 94

def call(env)
  env[:request_headers]["Authorization"] = "Bearer #{@token}" if @token
  @app.call(env)
end