Class: ShopifyClient::VerifyRequest

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

Constant Summary collapse

Error =
Class.new(Error)

Instance Method Summary collapse

Instance Method Details

#call(params) ⇒ Object

Verify that the request originated from Shopify.

Parameters:

  • params (Hash)

    the request params

Raises:

  • (Error)

    if signature is invalid



14
15
16
17
18
19
20
# File 'lib/shopify-client/verify_request.rb', line 14

def call(params)
  params = params.to_h.transform_keys(&:to_s)
  digest = OpenSSL::Digest::SHA256.new
  digest = OpenSSL::HMAC.hexdigest(digest, ShopifyClient.config.shared_secret, encoded_params(params))

  raise Error, 'invalid signature' unless digest == params['hmac']
end