Class: SSO::Server::Warden::Hooks::AfterAuthentication

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/sso/server/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, #logger, #progname, #warn

Constructor Details

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

Returns a new instance of AfterAuthentication.



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

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#userObject (readonly)

Returns the value of attribute user.



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

def user
  @user
end

#wardenObject (readonly)

Returns the value of attribute warden.



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

def warden
  @warden
end

Class Method Details

.to_procObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/sso/server/warden/hooks/after_authentication.rb', line 10

def self.to_proc
  proc do |user, warden, options|
    begin
      new(user: user, warden: warden, options: options).call
    rescue => exception
      ::SSO.config.exception_handler.call exception
      # The show must go on
    end
  end
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sso/server/warden/hooks/after_authentication.rb', line 25

def call
  debug { 'Starting hook because this is considered the first login of the current session...' }
  request = warden.request
  session = warden.env['rack.session']

  debug { "Generating a passport for user #{user.id.inspect} for the session with the SSO server..." }
  attributes = { owner_id: user.id, ip: request.ip, agent: request.user_agent }

  generation = SSO::Server::Passports.generate attributes
  if generation.success?
    debug { "Passport with ID #{generation.object.inspect} generated successfuly. Persisting it in session..." }
    session[:passport_id] = generation.object
  else
    fail generation.code.inspect + generation.object.inspect
  end

  debug { 'Finished.' }
end