From 55848e1000a292d8242147dbcb73de7f28d3cb2d Mon Sep 17 00:00:00 2001 From: tsoganov Date: Mon, 27 Jan 2025 16:26:20 +0200 Subject: [PATCH] Added birthday ident verification --- .../identification_requests_controller.rb | 6 ++-- .../repp/v1/contacts_controller.rb | 2 +- app/interactions/actions/contact_verify.rb | 34 +++++++++++++++---- app/services/eeid/identification_service.rb | 10 +++--- config/application.yml.sample | 6 ++-- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/app/controllers/eeid/webhooks/identification_requests_controller.rb b/app/controllers/eeid/webhooks/identification_requests_controller.rb index 219ec13756..6451caaccc 100644 --- a/app/controllers/eeid/webhooks/identification_requests_controller.rb +++ b/app/controllers/eeid/webhooks/identification_requests_controller.rb @@ -17,7 +17,7 @@ def create return render_invalid_signature unless valid_hmac_signature?(request.headers['X-HMAC-Signature']) contact = Contact.find_by_code(permitted_params[:reference]) - poi = catch_poi + poi = catch_poi(contact) verify_contact(contact) inform_registrar(contact, poi) render json: { status: 'success' }, status: :ok @@ -55,8 +55,8 @@ def verify_contact(contact) end end - def catch_poi - ident_service = Eeid::IdentificationService.new + def catch_poi(contact) + ident_service = Eeid::IdentificationService.new(contact.ident_type) response = ident_service.get_proof_of_identity(permitted_params[:identification_request_id]) raise StandardError, response[:error] if response[:error].present? diff --git a/app/controllers/repp/v1/contacts_controller.rb b/app/controllers/repp/v1/contacts_controller.rb index 7b60d8b235..cbb76e77cd 100644 --- a/app/controllers/repp/v1/contacts_controller.rb +++ b/app/controllers/repp/v1/contacts_controller.rb @@ -136,7 +136,7 @@ def verify desc 'Get proof of identity pdf file for a contact' def download_poi authorize! :verify, Epp::Contact - ident_service = Eeid::IdentificationService.new + ident_service = Eeid::IdentificationService.new(@contact.ident_type) response = ident_service.get_proof_of_identity(@contact.verification_id) send_data response[:data], filename: "proof_of_identity_#{@contact.verification_id}.pdf", diff --git a/app/interactions/actions/contact_verify.rb b/app/interactions/actions/contact_verify.rb index 8b9fd4fd08..3a272d1625 100644 --- a/app/interactions/actions/contact_verify.rb +++ b/app/interactions/actions/contact_verify.rb @@ -1,4 +1,7 @@ module Actions + # The ContactVerify class is responsible for handling the verification process + # for a contact, including creating identification requests and updating the + # contact's verification status. class ContactVerify attr_reader :contact @@ -7,10 +10,7 @@ def initialize(contact) end def call - if contact.verified_at.present? - contact.errors.add(:base, :verification_exists) - return - end + return false unless %w[priv birthday].include? contact.ident_type create_identification_request @@ -22,7 +22,7 @@ def call private def create_identification_request - ident_service = Eeid::IdentificationService.new + ident_service = Eeid::IdentificationService.new(contact.ident_type) response = ident_service.create_identification_request(request_payload) ContactMailer.identification_requested(contact: contact, link: response['link']).deliver_now rescue Eeid::IdentError => e @@ -31,6 +31,24 @@ def create_identification_request end def request_payload + if contact.ident_type == 'birthday' + birthday_payload + else + default_payload + end + end + + def birthday_payload + { + claims_required: [ + { type: 'birthdate', value: contact.ident }, + { type: 'name', value: contact.name } + ], + reference: contact.code + } + end + + def default_payload { claims_required: [{ type: 'sub', @@ -41,7 +59,11 @@ def request_payload end def commit - @contact.update(ident_request_sent_at: Time.zone.now) + @contact.update( + ident_request_sent_at: Time.zone.now, + verified_at: nil, + verification_id: nil + ) end end end diff --git a/app/services/eeid/identification_service.rb b/app/services/eeid/identification_service.rb index 5757b307ce..99604a9c08 100644 --- a/app/services/eeid/identification_service.rb +++ b/app/services/eeid/identification_service.rb @@ -3,11 +3,11 @@ module Eeid # This class handles identification services. class IdentificationService < Base - CLIENT_ID = ENV['ident_service_client_id'] - CLIENT_SECRET = ENV['ident_service_client_secret'] - - def initialize - super(CLIENT_ID, CLIENT_SECRET) + def initialize(ident_type = 'priv') + super( + ENV["#{ident_type}_ident_service_client_id"], + ENV["#{ident_type}_ident_service_client_secret"] + ) end def create_identification_request(request_params) diff --git a/config/application.yml.sample b/config/application.yml.sample index 31d6cdae7f..c906318664 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -261,5 +261,7 @@ whitelist_companies: - '87654321' eeid_base_url: 'http://eid.test' -ident_service_client_id: 123 -ident_service_client_secret: 321 +priv_ident_service_client_id: 123 +priv_ident_service_client_secret: 321 +birthday_ident_service_client_id: 456 +birthday_ident_service_client_secret: 654