Class: Vodka::Client::Middleware::SignedResponse
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- Vodka::Client::Middleware::SignedResponse
- Defined in:
- lib/vodka/client/middleware/signed_response.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #expected_response_signature ⇒ Object
- #ids_match? ⇒ Boolean
- #on_complete(env) ⇒ Object
- #request_id ⇒ Object
- #response_id ⇒ Object
- #response_signature ⇒ Object
- #signature_valid? ⇒ Boolean
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/vodka/client/middleware/signed_response.rb', line 5 def env @env end |
Instance Method Details
#expected_response_signature ⇒ Object
33 34 35 |
# File 'lib/vodka/client/middleware/signed_response.rb', line 33 def expected_response_signature Vodka::Client.config.digest.hexdigest([request_id, Vodka::Client.config.response_secret].join) end |
#ids_match? ⇒ Boolean
13 14 15 |
# File 'lib/vodka/client/middleware/signed_response.rb', line 13 def ids_match? request_id == response_id end |
#on_complete(env) ⇒ Object
7 8 9 10 11 |
# File 'lib/vodka/client/middleware/signed_response.rb', line 7 def on_complete(env) @env = env raise SecurityException.new('Response ID mismatch') unless ids_match? raise SecurityException.new('Invalid response signature') unless signature_valid? end |
#request_id ⇒ Object
21 22 23 |
# File 'lib/vodka/client/middleware/signed_response.rb', line 21 def request_id env[:request_headers]['X-Request-Id'] end |
#response_id ⇒ Object
25 26 27 |
# File 'lib/vodka/client/middleware/signed_response.rb', line 25 def response_id env[:response_headers]['x-response-id'] end |
#response_signature ⇒ Object
29 30 31 |
# File 'lib/vodka/client/middleware/signed_response.rb', line 29 def response_signature env[:response_headers]['x-response-signature'] end |
#signature_valid? ⇒ Boolean
17 18 19 |
# File 'lib/vodka/client/middleware/signed_response.rb', line 17 def signature_valid? response_signature == expected_response_signature end |