Class: SignIn::UserLoader

Inherits:
Object
  • Object
show all
Defined in:
app/services/sign_in/user_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token:, request_ip:) ⇒ UserLoader

Returns a new instance of UserLoader.



7
8
9
10
# File 'app/services/sign_in/user_loader.rb', line 7

def initialize(access_token:, request_ip:)
  @access_token = access_token
  @request_ip = request_ip
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'app/services/sign_in/user_loader.rb', line 5

def access_token
  @access_token
end

#request_ipObject (readonly)

Returns the value of attribute request_ip.



5
6
7
# File 'app/services/sign_in/user_loader.rb', line 5

def request_ip
  @request_ip
end

Instance Method Details

#authn_contextObject (private)



67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/services/sign_in/user_loader.rb', line 67

def authn_context
  case user_verification.credential_type
  when Constants::Auth::IDME
    user_is_verified? ? Constants::Auth::IDME_LOA3 : Constants::Auth::IDME_LOA1
  when Constants::Auth::DSLOGON
    user_is_verified? ? Constants::Auth::IDME_DSLOGON_LOA3 : Constants::Auth::IDME_DSLOGON_LOA1
  when Constants::Auth::MHV
    user_is_verified? ? Constants::Auth::IDME_MHV_LOA3 : Constants::Auth::IDME_MHV_LOA1
  when Constants::Auth::LOGINGOV
    user_is_verified? ? Constants::Auth::LOGIN_GOV_IAL2 : Constants::Auth::LOGIN_GOV_IAL1
  end
end

#current_userObject (private)



108
109
110
111
112
113
114
# File 'app/services/sign_in/user_loader.rb', line 108

def current_user
  return @current_user if @current_user

  user = User.new
  user.instance_variable_set(:@identity, user_identity)
  @current_user = user
end

#find_valid_userObject (private)



18
19
20
21
22
23
# File 'app/services/sign_in/user_loader.rb', line 18

def find_valid_user
  user = User.find(access_token.user_uuid)
  return unless user&.identity && user&.session_handle == access_token.session_handle

  user
end

#idme_or_logingov_serviceObject (private)



84
85
86
# File 'app/services/sign_in/user_loader.rb', line 84

def idme_or_logingov_service
  [:service_name] == Constants::Auth::IDME || [:service_name] == Constants::Auth::LOGINGOV
end

#loaObject (private)



56
57
58
59
# File 'app/services/sign_in/user_loader.rb', line 56

def loa
  current_loa = user_is_verified? ? Constants::Auth::LOA_THREE : Constants::Auth::LOA_ONE
  { current: current_loa, highest: Constants::Auth::LOA_THREE }
end

#multifactorObject (private)



80
81
82
# File 'app/services/sign_in/user_loader.rb', line 80

def multifactor
  user_is_verified? && idme_or_logingov_service
end

#performObject



12
13
14
# File 'app/services/sign_in/user_loader.rb', line 12

def perform
  find_valid_user || reload_user
end

#reload_userObject (private)



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/sign_in/user_loader.rb', line 25

def reload_user
  
  user_identity.uuid = access_token.user_uuid
  current_user.uuid = access_token.user_uuid
  current_user.last_signed_in = session.created_at
  current_user.fingerprint = request_ip
  current_user.session_handle = access_token.session_handle
  current_user.save && user_identity.save
  current_user.invalidate_mpi_cache
  current_user.

  current_user
end

#sessionObject (private)



92
93
94
# File 'app/services/sign_in/user_loader.rb', line 92

def session
  @session ||= OAuthSession.find_by(handle: access_token.session_handle)
end

#sign_inObject (private)



61
62
63
64
65
# File 'app/services/sign_in/user_loader.rb', line 61

def 
  { service_name: user_verification.credential_type,
    client_id: session.client_id,
    auth_broker: Constants::Auth::BROKER_CODE }
end

#user_accountObject (private)



96
97
98
# File 'app/services/sign_in/user_loader.rb', line 96

def 
  @user_account ||= session.
end

#user_attributesObject (private)



43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/services/sign_in/user_loader.rb', line 43

def user_attributes
  {
    mhv_icn: .icn,
    idme_uuid: user_verification.idme_uuid || user_verification.backing_idme_uuid,
    logingov_uuid: user_verification.logingov_uuid,
    loa:,
    email: session.credential_email,
    authn_context:,
    multifactor:,
    sign_in:
  }
end

#user_identityObject (private)



104
105
106
# File 'app/services/sign_in/user_loader.rb', line 104

def user_identity
  @user_identity ||= UserIdentity.new(user_attributes)
end

#user_is_verified?Boolean (private)

Returns:

  • (Boolean)


88
89
90
# File 'app/services/sign_in/user_loader.rb', line 88

def user_is_verified?
  .verified?
end

#user_verificationObject (private)



100
101
102
# File 'app/services/sign_in/user_loader.rb', line 100

def user_verification
  @user_verification ||= session.user_verification
end

#validate_account_and_sessionObject (private)



39
40
41
# File 'app/services/sign_in/user_loader.rb', line 39

def 
  raise Errors::SessionNotFoundError.new message: 'Invalid Session Handle' unless session
end