Class: Vodka::Server::Middleware::SignedRequest
- Inherits:
-
Object
- Object
- Vodka::Server::Middleware::SignedRequest
- Defined in:
- lib/vodka/server/middleware/signed_request.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #expected_request_signature ⇒ Object
- #forbidden ⇒ Object
-
#initialize(app, options = {}) ⇒ SignedRequest
constructor
A new instance of SignedRequest.
- #request_id ⇒ Object
- #request_signature ⇒ Object
- #request_signature_valid? ⇒ Boolean
- #response_signature ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ SignedRequest
Returns a new instance of SignedRequest.
7 8 9 |
# File 'lib/vodka/server/middleware/signed_request.rb', line 7 def initialize(app, = {}) @app, @options = app, end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
5 6 7 |
# File 'lib/vodka/server/middleware/signed_request.rb', line 5 def app @app end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/vodka/server/middleware/signed_request.rb', line 5 def env @env end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/vodka/server/middleware/signed_request.rb', line 11 def call(env) @env = env return app.call(env) if Vodka::Server.config.perform_request_signing == false return app.call(env) unless env['REQUEST_PATH'].start_with?(Vodka::Server.config.prefix) request_signature_valid? ? app.call(env) : forbidden end |
#expected_request_signature ⇒ Object
32 33 34 |
# File 'lib/vodka/server/middleware/signed_request.rb', line 32 def expected_request_signature Vodka::Server.config.digest.hexdigest([request_id, Vodka::Server.config.request_secret].join) end |
#forbidden ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/vodka/server/middleware/signed_request.rb', line 40 def forbidden headers = { 'Content-Type' => 'application/json; charset=utf-8', 'X-Response-Id' => request_id, 'X-Response-Signature' => response_signature } data = { data: nil, errors: { vodka_error: '403 Forbidden' }, metadata: {} } [403, headers, [MultiJson.dump(data)]] end |
#request_id ⇒ Object
24 25 26 |
# File 'lib/vodka/server/middleware/signed_request.rb', line 24 def request_id env['HTTP_X_REQUEST_ID'] end |
#request_signature ⇒ Object
28 29 30 |
# File 'lib/vodka/server/middleware/signed_request.rb', line 28 def request_signature env['HTTP_X_REQUEST_SIGNATURE'] end |
#request_signature_valid? ⇒ Boolean
20 21 22 |
# File 'lib/vodka/server/middleware/signed_request.rb', line 20 def request_signature_valid? request_signature == expected_request_signature end |