Class: Sso::Warden::Hooks::CreateMasterSession

Inherits:
Object
  • Object
show all
Includes:
Support
Defined in:
lib/sso/warden/hooks/create_master_session.rb

Instance Method Summary collapse

Methods included from Support

#initialize, #logged_in?, #scope, #session

Methods included from Logging

#debug, #error, #fatal, #info, #warn

Instance Method Details

#callObject



7
8
9
10
11
12
13
14
15
# File 'lib/sso/warden/hooks/create_master_session.rb', line 7

def call
  if logged_in?
    debug { "Starting hook because this is considered the first login of the current session..." }
    debug { "Log out previous Sso:Session if exists : ID session['sso_session_id']" }
    ::Sso::Session.logout(session["sso_session_id"])
    generate_session
  end
  return nil
end

#generate_sessionObject



17
18
19
20
21
22
23
24
# File 'lib/sso/warden/hooks/create_master_session.rb', line 17

def generate_session
  debug { "Generating a Sso:Session for user #{user.id.inspect} for the session cookie at the Sso server..." }
  attributes = {  ip: request.ip, agent: request.user_agent }

  sso_session = Sso::Session.generate_master(user, attributes)
  debug { "Sso:Session with ID #{sso_session.id} generated successfuly. Persisting it in session..." }
  session["sso_session_id"] = sso_session.id.to_s
end