Class: Sso::Warden::Hooks::AfterAuthentication

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

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

Constructor Details

#initialize(user:, warden:, options:) ⇒ AfterAuthentication

Returns a new instance of AfterAuthentication.



17
18
19
# File 'lib/sso/warden/hooks/after_authentication.rb', line 17

def initialize(user:, warden:, options:)
  @user, @warden, @options = user, warden, options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/sso/warden/hooks/after_authentication.rb', line 7

def options
  @options
end

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'lib/sso/warden/hooks/after_authentication.rb', line 7

def user
  @user
end

#wardenObject (readonly)

Returns the value of attribute warden.



7
8
9
# File 'lib/sso/warden/hooks/after_authentication.rb', line 7

def warden
  @warden
end

Class Method Details

.to_procObject



11
12
13
14
15
# File 'lib/sso/warden/hooks/after_authentication.rb', line 11

def self.to_proc
  proc do |user, warden, options|
    new(user: user, warden: warden, options: options).call
  end
end

Instance Method Details

#callObject



21
22
23
24
# File 'lib/sso/warden/hooks/after_authentication.rb', line 21

def call
  debug { "Starting hook because this is considered the first login of the current session..." }
  generate_session
end

#generate_sessionObject



26
27
28
29
30
31
32
33
# File 'lib/sso/warden/hooks/after_authentication.rb', line 26

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

#logged_in?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/sso/warden/hooks/after_authentication.rb', line 43

def logged_in?
  warden.authenticated?(:user) && session
end

#scopeObject



35
36
37
# File 'lib/sso/warden/hooks/after_authentication.rb', line 35

def scope
  scope = options[:scope]
end

#sessionObject



39
40
41
# File 'lib/sso/warden/hooks/after_authentication.rb', line 39

def session
  warden.session(scope)
end