Class: BasicAuth::Middleware
- Inherits:
-
Rack::Auth::Basic
- Object
- Rack::Auth::Basic
- BasicAuth::Middleware
- Defined in:
- lib/basic_auth/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
Override initialize to allow middleware options.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Override initialize to allow middleware options. IE:
use BasicAuth::Middleware, passwordfile: "htpasswd.txt"
9 10 11 12 |
# File 'lib/basic_auth/middleware.rb', line 9 def initialize(app, ={}) @app, = app, @passwordfile = [:passwordfile] || "config/htpasswd" end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/basic_auth/middleware.rb', line 14 def call(env) path = Rack::Request.new(env).path matcher = Matcher.new(path, ) return @app.call(env) unless matcher.match? # passthrough if route doesnt match htpasswd = Htpasswd.new(@passwordfile) = htpasswd.call(env) if @app.call(env) else # from Rack::Auth::Basic end end |