Class: Wix::Apps::SignedInstanceMiddleware
- Inherits:
-
Struct
- Object
- Struct
- Wix::Apps::SignedInstanceMiddleware
- Defined in:
- lib/wix-apps/signed_instance_middleware.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#paths ⇒ Object
Returns the value of attribute paths.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#secured_paths ⇒ Object
Returns the value of attribute secured_paths.
Instance Method Summary collapse
-
#call(env) ⇒ Array
Checks current URL path for Wix instance requirement, parses given signed instance and adds GET param ‘parsed_instance’ with the instance’s parsed properties.
-
#initialize(app, options = {}) ⇒ SignedInstanceMiddleware
constructor
Initializes the middleware to secure a given set of paths.
Constructor Details
#initialize(app, options = {}) ⇒ SignedInstanceMiddleware
Initializes the middleware to secure a given set of paths. Options: :secret_key - the Wix secret key as String :secured_paths (optional) - an Array of String and Regexp objects which every request’s path is matched against. Matching paths are required to pass a Wix signed instance.
9 10 11 12 13 14 |
# File 'lib/wix-apps/signed_instance_middleware.rb', line 9 def initialize(app, ={}) self.app = app self.secret_key = [:secret_key] self.secured_paths = [:secured_paths] || [] self.paths = [:paths] || [] end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app
3 4 5 |
# File 'lib/wix-apps/signed_instance_middleware.rb', line 3 def app @app end |
#paths ⇒ Object
Returns the value of attribute paths
3 4 5 |
# File 'lib/wix-apps/signed_instance_middleware.rb', line 3 def paths @paths end |
#secret_key ⇒ Object
Returns the value of attribute secret_key
3 4 5 |
# File 'lib/wix-apps/signed_instance_middleware.rb', line 3 def secret_key @secret_key end |
#secured_paths ⇒ Object
Returns the value of attribute secured_paths
3 4 5 |
# File 'lib/wix-apps/signed_instance_middleware.rb', line 3 def secured_paths @secured_paths end |
Instance Method Details
#call(env) ⇒ Array
Checks current URL path for Wix instance requirement, parses given signed instance and adds GET param ‘parsed_instance’ with the instance’s parsed properties.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wix-apps/signed_instance_middleware.rb', line 19 def call(env) path = env['PATH_INFO'] secured_path = secured_path? path if secured_path || path?(path) # path must be handled (instance is either required or optional) request = Rack::Request.new(env) env['wix.instance'] = nil if request.params.has_key? 'instance' # Wix' "instance" parameter was supplied so it must be parseable. parse and set it into env. begin env['wix.instance'] = Wix::Apps::SignedInstance.new(request.params['instance'], secret: secret_key) rescue Wix::Apps::SignedInstanceParseError # 403 Forbidden return [403, {}, ['Invalid Wix instance']] end elsif secured_path # instance is required but Wix' "instance" parameter is missing # 401 Unauthorized return [401, {}, ['Unauthorized']] end end app.call(env) end |