Class: ShopifyClient::VerifyWebhook

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify-client/verify_webhook.rb

Constant Summary collapse

Error =
Class.new(Error)

Instance Method Summary collapse

Instance Method Details

#call(data, hmac) ⇒ Object

Verify that the webhook request originated from Shopify.

Parameters:

  • data (String)

    the signed request data

  • hmac (String)

    the signature

Raises:

  • (Error)

    if signature is invalid



16
17
18
19
20
21
22
# File 'lib/shopify-client/verify_webhook.rb', line 16

def call(data, hmac)
  digest = OpenSSL::Digest::SHA256.new
  digest = OpenSSL::HMAC.digest(digest, ShopifyClient.config.shared_secret, data)
  digest = Base64.encode64(digest).strip

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