Class: Devise::Strategies::CasAuthenticatable

Inherits:
Base
  • Object
show all
Defined in:
lib/devise_cas_authenticatable/strategy.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!Object

Try to authenticate a user using the CAS ticket passed in params. If the ticket is valid and the model’s authenticate_with_cas_ticket method returns a user, then return success. If the ticket is invalid, then either fail (if we’re just returning from the CAS server, based on the referrer) or attempt to redirect to the CAS server’s login URL.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/devise_cas_authenticatable/strategy.rb', line 18

def authenticate!
  ticket = read_ticket(params)
  fail!(:invalid) if not ticket
  
  if resource = mapping.to.authenticate_with_cas_ticket(ticket)
    # Store the ticket in the session for later usage
    if ::Devise.cas_enable_single_sign_out
      session['cas_last_valid_ticket'] = ticket.ticket
      session['cas_last_valid_ticket_store'] = true
    end

    success!(resource)
  elsif ticket.is_valid?
    ido_id = ticket.respond_to?(:user) ? ticket.user : ticket.response.user
    redirect!(::Devise.cas_unregistered_url(request.url, mapping), :ido_id => ido_id)
    #fail!("The user #{ticket.response.user} is not registered with this site.  Please use a different account.")
  else
    fail!(:invalid)
  end
end

#valid?Boolean

True if the mapping supports authenticate_with_cas_ticket.

Returns:

  • (Boolean)


9
10
11
# File 'lib/devise_cas_authenticatable/strategy.rb', line 9

def valid?
  mapping.to.respond_to?(:authenticate_with_cas_ticket) && params[:ticket]
end