Class: Lucid::Shopify::VerifyWebhook

Inherits:
Object
  • Object
show all
Defined in:
lib/lucid/shopify/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



19
20
21
22
23
24
25
# 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