class ShopifyWebhook::Verifier

Attributes

request[R]
secret[R]

Public Class Methods

new(request, secret) click to toggle source
# File lib/shopify_webhook/verifier.rb, line 2
def initialize(request, secret)
  @request, @secret = request, secret
end

Public Instance Methods

call() click to toggle source
# File lib/shopify_webhook/verifier.rb, line 6
def call
  hmac == header
end

Private Instance Methods

data() click to toggle source
# File lib/shopify_webhook/verifier.rb, line 14
def data
  request.body.rewind
  request.body.read
end
digest() click to toggle source
# File lib/shopify_webhook/verifier.rb, line 30
def digest
  OpenSSL::Digest.new 'sha256'
end
header() click to toggle source
# File lib/shopify_webhook/verifier.rb, line 19
def header
  request.env['HTTP_X_SHOPIFY_HMAC_SHA256'] ||
  request.env['X-Shopify-Hmac-SHA256']
end
hmac() click to toggle source
# File lib/shopify_webhook/verifier.rb, line 24
def hmac
  Base64.encode64(
    OpenSSL::HMAC.digest(digest, secret, data)
  ).strip
end