Class: Auth::Middleware
- Inherits:
-
Rack::Auth::AbstractHandler
- Object
- Rack::Auth::AbstractHandler
- Auth::Middleware
- Defined in:
- lib/auth/middleware.rb
Defined Under Namespace
Classes: Request
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, realm = nil, options = {}, &authenticator) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, realm = nil, options = {}, &authenticator) ⇒ Middleware
Returns a new instance of Middleware.
10 11 12 13 |
# File 'lib/auth/middleware.rb', line 10 def initialize(app, realm=nil, ={}, &authenticator) super(app, realm, &authenticator) @options = end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/auth/middleware.rb', line 15 def call(env) auth = Request.new(env) unless @options[:allow_unauthenticated] return unless auth.provided? return bad_request unless auth.bearer? end if auth.provided? && valid?(auth) env['REMOTE_USER'] = auth.account_id return @app.call(env) end if @options[:allow_unauthenticated] res = @app.call(env) return [res[0], res[1].merge('WWW-Authenticate' => challenge), res[2]] else end end |