Class: Johac::Connection::Middleware::Authorization
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Johac::Connection::Middleware::Authorization
- Defined in:
- lib/johac/connection.rb
Overview
Adds Authorization header to all requests.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, scheme, access_key, secret_key) ⇒ Authorization
constructor
A new instance of Authorization.
Constructor Details
#initialize(app, scheme, access_key, secret_key) ⇒ Authorization
Returns a new instance of Authorization.
136 137 138 139 140 141 |
# File 'lib/johac/connection.rb', line 136 def initialize(app, scheme, access_key, secret_key) @scheme = scheme @access_key = access_key @secret_key = secret_key super(app) end |
Instance Method Details
#call(env) ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/johac/connection.rb', line 143 def call(env) if auth = case @scheme when :basic then "Basic #{basic_auth_token}" when :hmac then "hmac #{hmac_auth_token(env.url.path)}" end env[:request_headers]['Authorization'] = auth end @app.call(env) end |