Class: Wix::Apps::SignedInstanceMiddleware

Inherits:
Struct
  • Object
show all
Defined in:
lib/wix-apps/signed_instance_middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ SignedInstanceMiddleware

Returns a new instance of SignedInstanceMiddleware.



4
5
6
7
# File 'lib/wix-apps/signed_instance_middleware.rb', line 4

def initialize(app, options={})
  @app = app
  initialize_options options
end

Instance Attribute Details

#appObject

Returns the value of attribute app

Returns:

  • (Object)

    the current value of app



3
4
5
# File 'lib/wix-apps/signed_instance_middleware.rb', line 3

def app
  @app
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



3
4
5
# File 'lib/wix-apps/signed_instance_middleware.rb', line 3

def options
  @options
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/wix-apps/signed_instance_middleware.rb', line 9

def call(env)
  @env = env

  if secured_path?
    @request = Rack::Request.new(env)
    if have_instance?
      begin
        @instance = Wix::Apps::SignedInstance.new(@request.params['instance'],
                    secret: options[:secret_key])
      rescue Wix::Apps::SignedInstanceParseError => e
        return [403, {}, ['Invalid wix instance']]
      end

      if @instance.valid?
        parse_instance!
        @app.call(env)
      else
        [403, {}, ['Invalid wix instance']]
      end
    else
      [401, {}, ['Unauthorized']]
    end
  else
    @app.call(env)
  end

end