0

My folders are:

app/
-  -controllers/
-        -shopify_app/
-               -webhooks_controller.rb
lib/
-  -shopify_app/
-        -controller_concerns/
-               -webhook_verification.rb

webhook_verification.rb code is:

  module ShopifyApp
    module WebhookVerification
      extend ActiveSupport::Concern

      included do
        skip_before_action :verify_authenticity_token, raise: false
        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

I would like to include the webhook_verification.rb in webhooks_controller.rb doing "include ShopifyApp::WebhookVerification" but it doesn't work.

How can I load the lib folder?

Note: I've tried writing this on my config/application.rb but it doesn't seem to work

config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]
Gyntonic
  • 346
  • 2
  • 4
  • 14
  • 1
    did you restarted your server after that? – Ronan Lopes Jan 30 '18 at 16:28
  • Yes, I did... it still doesn't work @RonanLopes – Gyntonic Jan 30 '18 at 16:47
  • I've tried moving my lib/ folder into app/ folder and it raises me the error: "Unable to load application: ActiveSupport::Concern::MultipleIncludedBlocks: Cannot define multiple 'included' blocks for a Concern" @NikitaMisharin – Gyntonic Jan 30 '18 at 16:48

0 Answers0