-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LG-13963: 👤 Socure shadow mode background job (#11139)
* Add Socure configs to IdentityConfig * Add failure_message_when_negated to HaveLoggedEventMatcher * Add SocureShadowModeProofingJob Add job to make requests to Socure's KYC API and log the results alongside the original resolution proofing result. changelog: Upcoming Features, Identity verification, Add background job for Socure KYC proofing * Make ResolutionProofingJob schedule Socure KYC call - When flag is enabled, invoke Socure KYC as well * Add verified_attributes to resolution result to_h * Add more detail to resolution proofer logging test * Don't log TMX response body ong idv_socure_shadow_mode_proofing_result These are real big and mess with Cloudwatch's ability to parse fields out oflogs. * Tweak socure default base URL for dev * Remove pointless user_id arg to analytics event * Update app/jobs/socure_shadow_mode_proofing_job.rb Co-authored-by: Zach Margolis <[email protected]> * Clarify comment in spec * Clarify spec name * Clarify spec name * Use user.first_email * Revert "Use user.first_email" This reverts commit fd4dcab. * Remove pointless service_provider_issuer let --------- Co-authored-by: Zach Margolis <[email protected]>
- Loading branch information
1 parent
524983b
commit a52223a
Showing
11 changed files
with
630 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# frozen_string_literal: true | ||
|
||
class SocureShadowModeProofingJob < ApplicationJob | ||
include JobHelpers::StaleJobHelper | ||
|
||
queue_as :low | ||
|
||
discard_on JobHelpers::StaleJobHelper::StaleJobError | ||
|
||
# @param [String] document_capture_session_result_id | ||
# @param [String] encrypted_arguments | ||
# @param [String,nil] service_provider_issuer | ||
# @param [String] user_email | ||
# @param [String] user_uuid | ||
def perform( | ||
document_capture_session_result_id:, | ||
encrypted_arguments:, | ||
service_provider_issuer:, | ||
user_email:, | ||
user_uuid: | ||
) | ||
raise_stale_job! if stale_job?(enqueued_at) | ||
|
||
user = User.find_by(uuid: user_uuid) | ||
raise "User not found: #{user_uuid}" if !user | ||
|
||
analytics = create_analytics( | ||
user:, | ||
service_provider_issuer:, | ||
) | ||
|
||
proofing_result = load_proofing_result(document_capture_session_result_id:) | ||
if !proofing_result | ||
analytics.idv_socure_shadow_mode_proofing_result_missing | ||
return | ||
end | ||
|
||
applicant = build_applicant(encrypted_arguments:, user_email:) | ||
|
||
socure_result = proofer.proof(applicant) | ||
|
||
analytics.idv_socure_shadow_mode_proofing_result( | ||
resolution_result: format_proofing_result_for_logs(proofing_result), | ||
socure_result: socure_result.to_h, | ||
user_id: user.uuid, | ||
pii_like_keypaths: [ | ||
[:errors, :ssn], | ||
[:resolution_result, :context, :stages, :resolution, :errors, :ssn], | ||
[:resolution_result, :context, :stages, :residential_address, :errors, :ssn], | ||
[:resolution_result, :context, :stages, :threatmetrix, :response_body, :first_name], | ||
[:resolution_result, :context, :stages, :state_id, :state_id_jurisdiction], | ||
], | ||
) | ||
end | ||
|
||
def create_analytics( | ||
user:, | ||
service_provider_issuer: | ||
) | ||
Analytics.new( | ||
user:, | ||
request: nil, | ||
sp: service_provider_issuer, | ||
session: {}, | ||
) | ||
end | ||
|
||
def format_proofing_result_for_logs(proofing_result) | ||
proofing_result.to_h.tap do |hash| | ||
hash.dig(:context, :stages, :threatmetrix)&.delete(:response_body) | ||
end | ||
end | ||
|
||
def load_proofing_result(document_capture_session_result_id:) | ||
DocumentCaptureSession.new( | ||
result_id: document_capture_session_result_id, | ||
).load_proofing_result&.result | ||
end | ||
|
||
def build_applicant( | ||
encrypted_arguments:, | ||
user_email: | ||
) | ||
decrypted_arguments = JSON.parse( | ||
Encryption::Encryptors::BackgroundProofingArgEncryptor.new.decrypt(encrypted_arguments), | ||
symbolize_names: true, | ||
) | ||
|
||
applicant_pii = decrypted_arguments[:applicant_pii] | ||
|
||
{ | ||
**applicant_pii.slice( | ||
:first_name, | ||
:last_name, | ||
:address1, | ||
:address2, | ||
:city, | ||
:state, | ||
:zipcode, | ||
:phone, | ||
:dob, | ||
:ssn, | ||
), | ||
email: user_email, | ||
} | ||
end | ||
|
||
def proofer | ||
@proofer ||= Proofing::Socure::IdPlus::Proofer.new( | ||
Proofing::Socure::IdPlus::Config.new( | ||
api_key: IdentityConfig.store.socure_idplus_api_key, | ||
base_url: IdentityConfig.store.socure_idplus_base_url, | ||
timeout: IdentityConfig.store.socure_idplus_timeout_in_seconds, | ||
), | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.