Class: Booqable::Middleware::Auth::ApiKey
- Defined in:
- lib/booqable/middleware/auth/api_key.rb
Overview
Faraday middleware for API key authentication
This middleware adds Bearer token authentication to HTTP requests using a pre-configured API key. The API key is added to the Authorization header for each request unless already present.
For more info see: developers.booqable.com/#authentication-access-token
Constant Summary collapse
- TOKEN_ENDPOINT =
OAuth token endpoint (legacy reference)
"/api/boomerang/oauth/token"
Instance Method Summary collapse
-
#call(env) ⇒ Faraday::Response
Process the HTTP request and add API key authentication.
-
#initialize(app, options = {}) ⇒ ApiKey
constructor
Initialize the API key authentication middleware.
Constructor Details
#initialize(app, options = {}) ⇒ ApiKey
Initialize the API key authentication middleware
24 25 26 27 28 |
# File 'lib/booqable/middleware/auth/api_key.rb', line 24 def initialize(app, = {}) super(app) @api_key = .fetch(:api_key) end |
Instance Method Details
#call(env) ⇒ Faraday::Response
Process the HTTP request and add API key authentication
Adds the API key as a Bearer token in the Authorization header if no authorization header is already present, then passes the request to the next middleware in the stack.
38 39 40 41 42 |
# File 'lib/booqable/middleware/auth/api_key.rb', line 38 def call(env) env.request_headers["Authorization"] ||= "Bearer #{@api_key}" @app.call(env) end |