Class: Faraday::Request::HMACAuthentication
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::Request::HMACAuthentication
- Defined in:
- lib/faraday/request/hmac_authentication.rb
Overview
#self.sign_with = access_id
#Captivus::AuthHMAC.keys[access_id] = secret
end
Defined Under Namespace
Classes: CanonicalString
Constant Summary collapse
- KEY =
"Authorization".freeze
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Public.
- #hmac_auth_header(env) ⇒ Object
-
#initialize(app, token, secret, options = {}) ⇒ HMACAuthentication
constructor
A new instance of HMACAuthentication.
- #sign_request? ⇒ Boolean
Constructor Details
#initialize(app, token, secret, options = {}) ⇒ HMACAuthentication
Returns a new instance of HMACAuthentication.
43 44 45 46 47 48 49 |
# File 'lib/faraday/request/hmac_authentication.rb', line 43 def initialize(app, token, secret, = {}) .merge!(:signature => HMACAuthentication::CanonicalString) keys = {token => secret} @token, @secret = token, secret @auth = Captivus::AuthHMAC.new(keys, ) super(app) end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
41 42 43 |
# File 'lib/faraday/request/hmac_authentication.rb', line 41 def auth @auth end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
41 42 43 |
# File 'lib/faraday/request/hmac_authentication.rb', line 41 def secret @secret end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
41 42 43 |
# File 'lib/faraday/request/hmac_authentication.rb', line 41 def token @token end |
Instance Method Details
#call(env) ⇒ Object
Public
52 53 54 55 |
# File 'lib/faraday/request/hmac_authentication.rb', line 52 def call(env) env[:request_headers][KEY] ||= hmac_auth_header(env).to_s if sign_request? @app.call(env) end |
#hmac_auth_header(env) ⇒ Object
57 58 59 |
# File 'lib/faraday/request/hmac_authentication.rb', line 57 def hmac_auth_header(env) auth.(env, token, secret) end |
#sign_request? ⇒ Boolean
61 62 63 |
# File 'lib/faraday/request/hmac_authentication.rb', line 61 def sign_request? !!@token && !!@secret end |