Class: ComplyanceSDK::HTTP::AuthenticationMiddleware
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- ComplyanceSDK::HTTP::AuthenticationMiddleware
- Defined in:
- lib/complyance_sdk/http/authentication_middleware.rb
Overview
Faraday middleware for API key authentication
Instance Method Summary collapse
-
#call(env) ⇒ Object
Process the request.
-
#initialize(app, api_key) ⇒ AuthenticationMiddleware
constructor
Initialize the middleware.
Constructor Details
#initialize(app, api_key) ⇒ AuthenticationMiddleware
Initialize the middleware
11 12 13 14 |
# File 'lib/complyance_sdk/http/authentication_middleware.rb', line 11 def initialize(app, api_key) super(app) @api_key = api_key end |
Instance Method Details
#call(env) ⇒ Object
Process the request
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/complyance_sdk/http/authentication_middleware.rb', line 19 def call(env) # Add API key to headers env[:request_headers]["Authorization"] = "Bearer #{@api_key}" env[:request_headers]["X-API-Key"] = @api_key # Add SDK identification headers env[:request_headers]["User-Agent"] = "ComplyanceSDK-Ruby/#{ComplyanceSDK::VERSION}" env[:request_headers]["X-SDK-Version"] = ComplyanceSDK::VERSION env[:request_headers]["X-SDK-Language"] = "ruby" # Add request ID for tracing env[:request_headers]["X-Request-ID"] = generate_request_id @app.call(env) end |