Class: Auther::Gatekeeper

Inherits:
Object
  • Object
show all
Defined in:
lib/auther/gatekeeper.rb

Overview

Rack middleware that guards access to sensitive routes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application, settings = {}) ⇒ Gatekeeper

Returns a new instance of Gatekeeper.



10
11
12
13
# File 'lib/auther/gatekeeper.rb', line 10

def initialize application, settings = {}
  @application = application
  @settings = Auther::Settings.new settings
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



6
7
8
# File 'lib/auther/gatekeeper.rb', line 6

def application
  @application
end

#environmentObject (readonly)

Returns the value of attribute environment.



6
7
8
# File 'lib/auther/gatekeeper.rb', line 6

def environment
  @environment
end

#settingsObject (readonly)

Returns the value of attribute settings.



6
7
8
# File 'lib/auther/gatekeeper.rb', line 6

def settings
  @settings
end

Instance Method Details

#call(environment) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/auther/gatekeeper.rb', line 15

def call environment
  @environment = environment

  if authorized? request.path
    application.call environment
  else
    session[Auther::Keymaster.redirect_url_key] = request.path
    denied_response = response
    denied_response.redirect settings.url
    denied_response.finish
  end
end