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
#CrashLog::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.
42 43 44 45 46 47 48 |
# File 'lib/faraday/request/hmac_authentication.rb', line 42 def initialize(app, token, secret, = {}) .merge!(:signature => HMACAuthentication::CanonicalString) keys = {token => secret} @token, @secret = token, secret @auth = CrashLog::AuthHMAC.new(keys, ) super(app) end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
40 41 42 |
# File 'lib/faraday/request/hmac_authentication.rb', line 40 def auth @auth end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
40 41 42 |
# File 'lib/faraday/request/hmac_authentication.rb', line 40 def secret @secret end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
40 41 42 |
# File 'lib/faraday/request/hmac_authentication.rb', line 40 def token @token end |
Instance Method Details
#call(env) ⇒ Object
Public
51 52 53 54 |
# File 'lib/faraday/request/hmac_authentication.rb', line 51 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
56 57 58 |
# File 'lib/faraday/request/hmac_authentication.rb', line 56 def hmac_auth_header(env) auth.(env, token, secret) end |
#sign_request? ⇒ Boolean
60 61 62 |
# File 'lib/faraday/request/hmac_authentication.rb', line 60 def sign_request? !!@token && !!@secret end |