Sha256: 3e006701052408ea865431b95c56b1c077b915a36016a2527985d7a50d94ef1e

Contents?: true

Size: 785 Bytes

Versions: 17

Compression:

Stored size: 785 Bytes

Contents

module DiscoApp
  module CarrierRequestController
    extend ActiveSupport::Concern

    included do
      before_action :verify_carrier_request_signature
    end

    private

      def verify_carrier_request_signature
        unless carrier_request_signature_is_valid?
          head :unauthorized
        end
      end

      def carrier_request_signature_is_valid?
        return true unless Rails.env.production?
        data = request.body.read.to_s
        hmac_header = request.headers['HTTP_X_SHOPIFY_HMAC_SHA256']
        digest  = OpenSSL::Digest::Digest.new('sha256')
        calculated_hmac = Base64.encode64(OpenSSL::HMAC.digest(digest, ShopifyApp.configuration.secret, data)).strip
        request.body.rewind
        calculated_hmac == hmac_header
      end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
disco_app-0.5.0 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.5.1 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.5.2 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.5.3 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.5.4 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.5.5 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.5.6 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.6.0 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.6.1 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.6.2 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.6.3 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.6.4 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.6.5 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.6.6 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.6.7 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.6.8 app/controllers/disco_app/carrier_request_controller.rb
disco_app-0.6.9 app/controllers/disco_app/carrier_request_controller.rb