Skip to content

Commit

Permalink
Added birthday ident verification
Browse files Browse the repository at this point in the history
  • Loading branch information
tsoganov committed Jan 27, 2025
1 parent 34da6f2 commit 55848e1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/repp/v1/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 28 additions & 6 deletions app/interactions/actions/contact_verify.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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',
Expand All @@ -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
10 changes: 5 additions & 5 deletions app/services/eeid/identification_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions config/application.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 55848e1

Please sign in to comment.