Class: Astroapi::HTTP::Middleware::Authentication

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

Overview

Faraday middleware to add Bearer token authentication

Instance Method Summary collapse

Constructor Details

#initialize(app, config) ⇒ Authentication

Returns a new instance of Authentication.



8
9
10
11
# File 'lib/astroapi/http/middleware/authentication.rb', line 8

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

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
# File 'lib/astroapi/http/middleware/authentication.rb', line 13

def call(env)
  if @config.api_key && !env.request_headers['Authorization']
    env.request_headers['Authorization'] = "Bearer #{@config.api_key}"
  end
  @app.call(env)
end