I am trying to configure an app proxy so users can submit a product for a Shopify store. I have seen multiple ways to so a signature and handle it so yet I am unable to get it working so the ShopifyAPI will work. The action is below, I noticed that:shopify_session filter only works for admin, not customers as well.
def submit_product
query_parameters = Rack::Utils.parse_query(request.query_string)
# Remove and save the "signature" entry
signature = query_parameters.delete("signature")
sorted_params = query_parameters.collect{ |k, v| "#{k}=#{Array(v).join(',')}" }.sort.join
calculated_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha256'), ENV['SHOPIFY_SECRET'], sorted_params)
raise 'Invalid signature' if signature != calculated_signature
@store = Store.where(shopify_url: query_parameters['shop']).first
if @store.present?
@product = @store.products.new
@product.images.build
@product_types = ShopifyAPI::CustomCollection.find(@store.customizable_collection_id).products
end
end