Sha256: 88fad5228e84d07938543897f8878684eb515b0ce33cf6b9cec35dbf428237c5

Contents?: true

Size: 1009 Bytes

Versions: 7

Compression:

Stored size: 1009 Bytes

Contents

module DiscoApp::Concerns::AppProxyController

  extend ActiveSupport::Concern

  included do
    before_action :verify_proxy_signature
    before_action :shopify_shop
    after_action :add_liquid_header

    rescue_from ActiveRecord::RecordNotFound do |_exception|
      render_error 404
    end
  end

  private

    def verify_proxy_signature
      head :unauthorized unless proxy_signature_is_valid?
    end

    def proxy_signature_is_valid?
      return true if (Rails.env.development? || Rails.env.test?) && DiscoApp.configuration.skip_proxy_verification?

      DiscoApp::ProxyService.proxy_signature_is_valid?(request.query_string, ShopifyApp.configuration.secret)
    end

    def shopify_shop
      @shop = DiscoApp::Shop.find_by!(shopify_domain: params[:shop])
    end

    def add_liquid_header
      response.headers['Content-Type'] = 'application/liquid'
    end

    def render_error(status)
      add_liquid_header
      render "disco_app/proxy_errors/#{status}", status: status
    end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
disco_app-0.17.0 app/controllers/disco_app/concerns/app_proxy_controller.rb
disco_app-0.18.0 app/controllers/disco_app/concerns/app_proxy_controller.rb
disco_app-0.18.2 app/controllers/disco_app/concerns/app_proxy_controller.rb
disco_app-0.18.3 app/controllers/disco_app/concerns/app_proxy_controller.rb
disco_app-0.18.6 app/controllers/disco_app/concerns/app_proxy_controller.rb
disco_app-0.18.4 app/controllers/disco_app/concerns/app_proxy_controller.rb
disco_app-0.18.1 app/controllers/disco_app/concerns/app_proxy_controller.rb