Class: SignIn::UserCodeMapCreator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_attributes:, state_payload:, verified_icn:, request_ip:) ⇒ UserCodeMapCreator

Returns a new instance of UserCodeMapCreator.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/sign_in/user_code_map_creator.rb', line 17

def initialize(user_attributes:, state_payload:, verified_icn:, request_ip:)
  @state_payload = state_payload
  @idme_uuid = user_attributes[:idme_uuid]
  @logingov_uuid = user_attributes[:logingov_uuid]
  @credential_email = user_attributes[:csp_email]
  @all_credential_emails = user_attributes[:all_csp_emails]
  @edipi = user_attributes[:edipi]
  @mhv_correlation_id = user_attributes[:mhv_correlation_id]
  @verified_icn = verified_icn
  @request_ip = request_ip
  @first_name = user_attributes[:first_name]
  @last_name = user_attributes[:last_name]
end

Instance Attribute Details

#all_credential_emailsObject (readonly)

Returns the value of attribute all_credential_emails.



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

def all_credential_emails
  @all_credential_emails
end

#credential_emailObject (readonly)

Returns the value of attribute credential_email.



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

def credential_email
  @credential_email
end

#edipiObject (readonly)

Returns the value of attribute edipi.



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

def edipi
  @edipi
end

#first_nameObject (readonly)

Returns the value of attribute first_name.



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

def first_name
  @first_name
end

#idme_uuidObject (readonly)

Returns the value of attribute idme_uuid.



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

def idme_uuid
  @idme_uuid
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



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

def last_name
  @last_name
end

#logingov_uuidObject (readonly)

Returns the value of attribute logingov_uuid.



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

def logingov_uuid
  @logingov_uuid
end

#mhv_correlation_idObject (readonly)

Returns the value of attribute mhv_correlation_id.



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

def mhv_correlation_id
  @mhv_correlation_id
end

#request_ipObject (readonly)

Returns the value of attribute request_ip.



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

def request_ip
  @request_ip
end

#state_payloadObject (readonly)

Returns the value of attribute state_payload.



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

def state_payload
  @state_payload
end

#verified_icnObject (readonly)

Returns the value of attribute verified_icn.



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

def verified_icn
  @verified_icn
end

Instance Method Details

#access_token_attributesObject (private)



106
107
108
109
110
111
# File 'app/services/sign_in/user_code_map_creator.rb', line 106

def access_token_attributes
  { first_name:,
    last_name:,
    email: credential_email,
    all_emails: all_credential_emails }.compact
end

#client_configObject (private)



117
118
119
# File 'app/services/sign_in/user_code_map_creator.rb', line 117

def client_config
  @client_config ||= SignIn::ClientConfig.find_by!(client_id: state_payload.client_id)
end

#create_code_containerObject (private)



55
56
57
58
59
60
61
62
63
# File 'app/services/sign_in/user_code_map_creator.rb', line 55

def create_code_container
  CodeContainer.new(code: ,
                    client_id: state_payload.client_id,
                    code_challenge: state_payload.code_challenge,
                    user_verification_id: user_verification.id,
                    credential_email:,
                    user_attributes: access_token_attributes,
                    device_sso:).save!
end

#create_credential_emailObject (private)



42
43
44
45
# File 'app/services/sign_in/user_code_map_creator.rb', line 42

def create_credential_email
  Login::UserCredentialEmailUpdater.new(credential_email:,
                                        user_verification:).perform
end

#create_terms_code_containerObject (private)



51
52
53
# File 'app/services/sign_in/user_code_map_creator.rb', line 51

def create_terms_code_container
  TermsCodeContainer.new(code: terms_code, user_account_uuid: .id).save!
end

#create_user_acceptable_verified_credentialObject (private)



47
48
49
# File 'app/services/sign_in/user_code_map_creator.rb', line 47

def create_user_acceptable_verified_credential
  Login::UserAcceptableVerifiedCredentialUpdater.new(user_account:).perform
end

#device_ssoObject (private)



65
66
67
# File 'app/services/sign_in/user_code_map_creator.rb', line 65

def device_sso
  state_payload.scope == Constants::Auth::DEVICE_SSO
end

#login_codeObject (private)



121
122
123
# File 'app/services/sign_in/user_code_map_creator.rb', line 121

def 
  @login_code ||= SecureRandom.uuid
end

#needs_accepted_terms_of_use?Boolean (private)

Returns:

  • (Boolean)


113
114
115
# File 'app/services/sign_in/user_code_map_creator.rb', line 113

def needs_accepted_terms_of_use?
  client_config.va_terms_enforced? && .needs_accepted_terms_of_use?
end

#performObject



31
32
33
34
35
36
37
38
# File 'app/services/sign_in/user_code_map_creator.rb', line 31

def perform
  create_credential_email
  create_user_acceptable_verified_credential
  create_terms_code_container if needs_accepted_terms_of_use?
  create_code_container

  user_code_map
end

#sign_inObject (private)



94
95
96
97
98
99
100
# File 'app/services/sign_in/user_code_map_creator.rb', line 94

def 
  @sign_in ||= {
    service_name: state_payload.type,
    auth_broker: Constants::Auth::BROKER_CODE,
    client_id: state_payload.client_id
  }
end

#terms_codeObject (private)



125
126
127
128
129
# File 'app/services/sign_in/user_code_map_creator.rb', line 125

def terms_code
  return nil unless needs_accepted_terms_of_use?

  @terms_code ||= SecureRandom.uuid
end

#user_accountObject (private)



90
91
92
# File 'app/services/sign_in/user_code_map_creator.rb', line 90

def 
  @user_account ||= user_verification.
end

#user_code_mapObject (private)



78
79
80
81
82
83
84
# File 'app/services/sign_in/user_code_map_creator.rb', line 78

def user_code_map
  @user_code_map ||= UserCodeMap.new(login_code:,
                                     type: state_payload.type,
                                     client_state: state_payload.client_state,
                                     client_config:,
                                     terms_code:)
end

#user_uuidObject (private)



102
103
104
# File 'app/services/sign_in/user_code_map_creator.rb', line 102

def user_uuid
  @user_uuid ||= user_verification.backing_credential_identifier
end

#user_verificationObject (private)



86
87
88
# File 'app/services/sign_in/user_code_map_creator.rb', line 86

def user_verification
  @user_verification ||= Login::UserVerifier.new(user_verifier_object).perform
end

#user_verifier_objectObject (private)



69
70
71
72
73
74
75
76
# File 'app/services/sign_in/user_code_map_creator.rb', line 69

def user_verifier_object
  @user_verifier_object ||= OpenStruct.new({ idme_uuid:,
                                             logingov_uuid:,
                                             sign_in:,
                                             edipi:,
                                             mhv_correlation_id:,
                                             icn: verified_icn })
end