Class: Rack::Casual::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/casual/authentication.rb

Overview

How it works

  1. Request enters app

  2. Is params present with a valid CAS ticket

  3. ‘- Validate ticket

    If valid find or create user
    User not ok? -- show bad info, don't redirect back to cas
    User ok? -- set user.id in session and continue
    
  4. Is response a 401?

  5. ‘- Authenticate using auth_token if auth_token is present `- Or redirect to CAS

  6. Done

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Authentication

Returns a new instance of Authentication.



21
22
23
# File 'lib/rack/casual/authentication.rb', line 21

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rack/casual/authentication.rb', line 25

def call(env)
  @request  = Rack::Request.new(env)
  @env = env

  # Skip middleware if ignore_url is set and matches request.path
  if Rack::Casual.ignore_url && @request.path.match(Rack::Casual.ignore_url)
    @app.call(env)
  else
    unless process_request_from_cas
      @app.call(env)
    else
      handle_401(@app.call(env))
    end
  end
end