Class: Vodka::Client::Middleware::SignedResponse

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/vodka/client/middleware/signed_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envObject (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_signatureObject



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

Returns:

  • (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

Raises:



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_idObject



21
22
23
# File 'lib/vodka/client/middleware/signed_response.rb', line 21

def request_id
  env[:request_headers]['X-Request-Id']
end

#response_idObject



25
26
27
# File 'lib/vodka/client/middleware/signed_response.rb', line 25

def response_id
  env[:response_headers]['x-response-id']
end

#response_signatureObject



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

Returns:

  • (Boolean)


17
18
19
# File 'lib/vodka/client/middleware/signed_response.rb', line 17

def signature_valid?
  response_signature == expected_response_signature
end