Sha256: cbc6df9c0e6d63d50f78ff1e36bc2abad6bf0ba8159b9d42671d9988bbbf7ce4

Contents?: true

Size: 905 Bytes

Versions: 5

Compression:

Stored size: 905 Bytes

Contents

module ShopifyApp
  module WebhookVerification
    extend ActiveSupport::Concern

    included do
      if Rails.version >= '5.0'
        skip_before_action :verify_authenticity_token, raise: false
      else
        skip_before_action :verify_authenticity_token
      end

      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.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

5 entries across 5 versions & 1 rubygems

Version Path
shopify_app-7.2.8 lib/shopify_app/webhook_verification.rb
shopify_app-7.2.7 lib/shopify_app/webhook_verification.rb
shopify_app-7.2.6 lib/shopify_app/webhook_verification.rb
shopify_app-7.2.5 lib/shopify_app/webhook_verification.rb
shopify_app-7.2.3 lib/shopify_app/webhook_verification.rb