Class: Aserto::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/aserto/authorization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) {|@config| ... } ⇒ Authorization

Returns a new instance of Authorization.

Yields:



7
8
9
10
11
# File 'lib/aserto/authorization.rb', line 7

def initialize(app, options = {})
  @app = app
  @config = Aserto.config(options)
  yield @config if block_given?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/aserto/authorization.rb', line 5

def config
  @config
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/aserto/authorization.rb', line 13

def call(env)
  request = Rack::Request.new(env)

  allowed = if enabled?(request)
              Aserto.logger.debug("Aserto authorization enabled")
              client = Aserto::AuthClient.new(request)
              res = client.is
              Aserto.logger.debug("Aserto authorization result -> allowed: #{res}")
              res
            else
              Aserto.logger.debug("Aserto authorization not enabled")
              true
            end

  return @app.call env if allowed

  config.on_unauthorized.call(env)
end