提问者:小点点

Shopify API App Proxy with Rails验证用户


我正在尝试配置应用程序代理,以便用户可以向Shopify商店提交产品。我已经看到了多种方法,所以签名和处理它,但我无法让它的工作,使ShopifAPI将工作。操作如下,我注意到:shopify_会话过滤器仅适用于管理员,不适用于客户。

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

共1个答案

匿名用户

在连接到ShopifyAPI之前,应首先建立API会话。否则,shopifigapi::CustomCollection。find方法无法连接到Shopify。shopify_api自述文件的步骤3和4包括以下示例:

session = ShopifyAPI::Session.new("SHOP_NAME.myshopify.com", token)
ShopifyAPI::Base.activate_session(session)
product_types = ShopifyAPI::CustomCollection.find(id)

token是您可以在OAuth身份验证阶段(将应用程序安装到商店中)请求的永久访问令牌。