class BasicAuth::Middleware
Public Class Methods
new(app, options={})
click to toggle source
Override initialize to allow middleware options. IE:
use BasicAuth::Middleware, passwordfile: "htpasswd.txt"
# File lib/basic_auth/middleware.rb, line 9 def initialize(app, options={}) @app, @options = app, options @passwordfile = options[:passwordfile] || "config/htpasswd" end
Public Instance Methods
call(env)
click to toggle source
# File lib/basic_auth/middleware.rb, line 14 def call(env) path = Rack::Request.new(env).path matcher = Matcher.new(path, @options) return @app.call(env) unless matcher.match? # passthrough if route doesnt match htpasswd = Htpasswd.new(@passwordfile) authorized = htpasswd.call(env) if authorized @app.call(env) else unauthorized # from Rack::Auth::Basic end end