15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/webhookdb/intercom.rb', line 15
def self.webhook_response(request, webhook_secret)
= request.env["HTTP_X_HUB_SIGNATURE"]
return Webhookdb::WebhookResponse.error("missing hmac") if .nil?
request.body.rewind
request_data = request.body.read
hmac = OpenSSL::HMAC.hexdigest("SHA1", webhook_secret, request_data)
calculated_hmac = "sha1=#{hmac}"
verified = ActiveSupport::SecurityUtils.secure_compare(calculated_hmac, )
return Webhookdb::WebhookResponse.ok if verified
return Webhookdb::WebhookResponse.error("invalid hmac")
end
|