2020-04-03 07:34:58 +00:00
|
|
|
class Api::V1::Widget::ContactsController < Api::V1::Widget::BaseController
|
2021-03-20 12:14:20 +00:00
|
|
|
before_action :process_hmac
|
|
|
|
|
|
|
|
def show; end
|
|
|
|
|
2020-04-03 07:34:58 +00:00
|
|
|
def update
|
|
|
|
contact_identify_action = ContactIdentifyAction.new(
|
|
|
|
contact: @contact,
|
|
|
|
params: permitted_params.to_h.deep_symbolize_keys
|
|
|
|
)
|
|
|
|
render json: contact_identify_action.perform
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-01-17 17:14:03 +00:00
|
|
|
def process_hmac
|
2021-11-11 04:18:38 +00:00
|
|
|
return if params[:identifier_hash].blank? && !@web_widget.hmac_mandatory
|
|
|
|
|
|
|
|
render json: { error: 'HMAC failed: Invalid Identifier Hash Provided' }, status: :unauthorized unless valid_hmac?
|
2021-01-17 17:14:03 +00:00
|
|
|
|
|
|
|
@contact_inbox.update(hmac_verified: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid_hmac?
|
|
|
|
params[:identifier_hash] == OpenSSL::HMAC.hexdigest(
|
|
|
|
'sha256',
|
|
|
|
@web_widget.hmac_token,
|
|
|
|
params[:identifier].to_s
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-04-03 07:34:58 +00:00
|
|
|
def permitted_params
|
2021-08-13 11:56:09 +00:00
|
|
|
params.permit(:website_token, :identifier, :identifier_hash, :email, :name, :avatar_url, :phone_number, custom_attributes: {})
|
2020-04-03 07:34:58 +00:00
|
|
|
end
|
|
|
|
end
|