Module: Webhookdb::Intercom

Includes:
Appydays::Configurable
Defined in:
lib/webhookdb/intercom.rb

Class Method Summary collapse

Class Method Details

.auth_headers(token) ⇒ Object



27
28
29
# File 'lib/webhookdb/intercom.rb', line 27

def self.auth_headers(token)
  return {"Intercom-Version" => "2.9", "Authorization" => "Bearer #{token}"}
end

.webhook_response(request, webhook_secret) ⇒ Object



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)
  header_value = request.env["HTTP_X_HUB_SIGNATURE"]
  return Webhookdb::WebhookResponse.error("missing hmac") if header_value.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, header_value)
  return Webhookdb::WebhookResponse.ok if verified
  return Webhookdb::WebhookResponse.error("invalid hmac")
end