class Lucid::Shopify::VerifyWebhook

Constants

Error

Public Instance Methods

call(data, hmac) click to toggle source

Verify that the webhook request originated from Shopify.

@param data [String] the signed request data @param hmac [String] the signature

@raise [Error] if signature is invalid

# File lib/lucid/shopify/verify_webhook.rb, line 19
def call(data, hmac)
  digest = OpenSSL::Digest::SHA256.new
  digest = OpenSSL::HMAC.digest(digest, Shopify.config.shared_secret, data)
  digest = Base64.encode64(digest).strip

  raise Error, 'invalid signature' unless digest == hmac
end