Class: Katalyst::Basic::Auth::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/katalyst/basic/auth/middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



9
10
11
# File 'lib/katalyst/basic/auth/middleware.rb', line 9

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



7
8
9
# File 'lib/katalyst/basic/auth/middleware.rb', line 7

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/katalyst/basic/auth/middleware.rb', line 13

def call(env)
  config = Config.for_path(env["PATH_INFO"])
  return @app.call(env) unless config.enabled?
  return @app.call(env) if config.allow_ip?(env)

  auth = Rack::Auth::Basic.new(app) do |u, p|
    u == config.username && p == config.password
  end
  auth.call env
end