Class: Machina::Middleware::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/machina/middleware/authentication.rb,
lib/machina/middleware/authentication/hints.rb

Overview

Rack middleware that extracts authentication tokens from incoming requests, resolves them against the identity service, and sets Current.authorized.

Defined Under Namespace

Classes: Hints

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Authentication

Returns a new instance of Authentication.



17
18
19
# File 'lib/machina/middleware/authentication.rb', line 17

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/machina/middleware/authentication.rb', line 21

def call(env)
  request = ActionDispatch::Request.new(env)
  return @app.call(env) if callback_path?(request) || skip_path?(request)

  token = extract_token(request)
  return @app.call(env) if token.blank?

  dispatch_session(env, request, token, Hints.from(env, request))
ensure
  Machina::Current.reset
end