Sha256: a42a31777d79bd35dbe141de4ea191132a3e5d6bb0d5dc1f3f246bd784fdaed5

Contents?: true

Size: 796 Bytes

Versions: 10

Compression:

Stored size: 796 Bytes

Contents

module ShopifyApp
  module WebhookVerification
    extend ActiveSupport::Concern

    included do
      skip_before_action :verify_authenticity_token
      before_action :verify_request
    end

    private

    def verify_request
      data = request.raw_post
      return head :unauthorized unless hmac_valid?(data)
    end

    def hmac_valid?(data)
      secret = ShopifyApp.configuration.secret
      digest = OpenSSL::Digest.new('sha256')
      ActiveSupport::SecurityUtils.variable_size_secure_compare(
        shopify_hmac,
        Base64.encode64(OpenSSL::HMAC.digest(digest, secret, data)).strip
      )
    end

    def shop_domain
      request.headers['HTTP_X_SHOPIFY_SHOP_DOMAIN']
    end

    def shopify_hmac
      request.headers['HTTP_X_SHOPIFY_HMAC_SHA256']
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
shopify_app-7.0.10 lib/shopify_app/webhook_verification.rb
shopify_app-7.0.9 lib/shopify_app/webhook_verification.rb
shopify_app-7.0.8 lib/shopify_app/webhook_verification.rb
shopify_app-7.0.7 lib/shopify_app/webhook_verification.rb
shopify_app-7.0.6 lib/shopify_app/webhook_verification.rb
shopify_app-7.0.5 lib/shopify_app/webhook_verification.rb
shopify_app-7.0.4 lib/shopify_app/webhook_verification.rb
shopify_app-7.0.2 lib/shopify_app/webhook_verification.rb
shopify_app-7.0.1 lib/shopify_app/webhook_verification.rb
shopify_app-7.0.0 lib/shopify_app/webhook_verification.rb