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
16
17
18
# File 'lib/sso/warden/hooks/create_master_session.rb', line 7

def call
  unless logged_in?
    throw(:warden)
    raise "DoorkeeperSso : CreateMasterSession requires an authenticated session" and return
  end

  debug { "NEW USER WARDEN SESSION" }
  debug { "Log out previous Sso:Session if exists : ID #{session['sso_session_id']}" }
  ::Sso::Session.logout(session["sso_session_id"])
  generate_session
  return nil
end

#generate_sessionObject



20
21
22
23
24
25
26
27
# File 'lib/sso/warden/hooks/create_master_session.rb', line 20

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