Module: SqAuth::SqAuthIntegration::SqAuthRackProtection

Defined in:
lib/sq_auth/sq_auth_integration/sq_auth_rack_protection.rb

Class Method Summary collapse

Class Method Details

.alter_environment(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sq_auth/sq_auth_integration/sq_auth_rack_protection.rb', line 9

def self.alter_environment options={}
  # Sorry, Konstantin
  except_host = options[:host]
  Rack::Protection::RemoteToken.class_exec(except_host) do |except|
    Rack::Protection::RemoteToken.const_set("HOST", except)
    alias :old_accepts? :accepts?
    def accepts?(env)
      form_hash = Rack::Request.new(env).params
      if referrer(env) == Rack::Protection::RemoteToken::HOST && env["REQUEST_METHOD"] == "POST" && form_hash.keys.include?("sqauthsession")
        true
      else
        old_accepts?(env)
      end
    end
  end
end

.check_environmentObject



5
6
7
# File 'lib/sq_auth/sq_auth_integration/sq_auth_rack_protection.rb', line 5

def self.check_environment
  defined?(Rack::Protection::RemoteToken)
end