Class: Routemaster::Middleware::Authenticate
- Inherits:
-
Object
- Object
- Routemaster::Middleware::Authenticate
- Includes:
- Wisper::Publisher
- Defined in:
- lib/routemaster/middleware/authenticate.rb
Overview
Authenticates requests according to the Routemaster spec.
Broadcasts :authenticate
with one of :missing
, failed
, or
:succeeded
.
This is very close to Rack::Auth::Basic
, in that HTTP Basic
is used; but the password part is ignored. In other words, this performs
token authentication using HTTP Basic.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Authenticate
constructor
options[:uuid] [Enumerable] a set of accepted authentication tokens.
Constructor Details
#initialize(app, options = {}) ⇒ Authenticate
options[:uuid] [Enumerable] a set of accepted authentication tokens
20 21 22 23 24 25 26 27 |
# File 'lib/routemaster/middleware/authenticate.rb', line 20 def initialize(app, = {}) @app = app @uuid = .fetch(:uuid) { Config.drain_tokens } unless @uuid.kind_of?(String) || @uuid.kind_of?(Enumerable) raise ArgumentError, ':uuid must be a String or Enumerable' end end |
Instance Method Details
#call(env) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/routemaster/middleware/authenticate.rb', line 29 def call(env) unless _has_auth?(env) publish(:authenticate, :missing, env) return [401, {}, []] end unless _valid_auth?(env) publish(:authenticate, :failed, env) return [403, {}, []] end publish(:authenticate, :succeeded, env) @app.call(env) end |