Class: IAMSSOeOAuth::SessionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/iam_ssoe_oauth/session_manager.rb

Constant Summary collapse

STATSD_OAUTH_SESSION_KEY =
'iam_ssoe_oauth.session'

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ SessionManager

Returns a new instance of SessionManager.



9
10
11
12
# File 'lib/iam_ssoe_oauth/session_manager.rb', line 9

def initialize(access_token)
  @access_token = access_token
  @session = IAMSession.find(access_token)
end

Instance Method Details

#find_or_create_userObject



14
15
16
17
18
# File 'lib/iam_ssoe_oauth/session_manager.rb', line 14

def find_or_create_user
  return IAMUser.find(@session.uuid) if @session

  create_user_session
end

#logoutObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/iam_ssoe_oauth/session_manager.rb', line 20

def logout
  uuid = @session.uuid
  Rails.logger.info('IAMUser logout: start', uuid:)

  identity_destroy_count = IAMUserIdentity.find(uuid).destroy
  user_destroy_count = IAMUser.find(uuid).destroy
  session_destroy_count = @session.destroy

  # redis returns number of records successfully deleted
  if [identity_destroy_count, user_destroy_count, session_destroy_count].all?(&:positive?)
    Rails.logger.info('IAMUser logout: success', uuid:)
    true
  else
    Rails.logger.warn('IAMUser logout: failure', uuid:, status: {
                        identity_destroy_count:,
                        user_destroy_count:,
                        session_destroy_count:
                      })
    false
  end
end