Ruby on rails ShopifAPI应用程序代理与Rails验证用户

Ruby on rails ShopifAPI应用程序代理与Rails验证用户,ruby-on-rails,ruby,oauth-2.0,shopify,Ruby On Rails,Ruby,Oauth 2.0,Shopify,我正在尝试配置应用程序代理,以便用户可以向Shopify商店提交产品。我已经看到了多种方法,所以签名和处理它,但我无法让它的工作,使ShopifAPI将工作。操作如下,我注意到:shopify_会话过滤器仅适用于管理员,不适用于客户 def submit_product query_parameters = Rack::Utils.parse_query(request.query_string) # Remove and save the "signature" entry

我正在尝试配置应用程序代理,以便用户可以向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

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

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

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

如果使用如何获取令牌?该应用程序有一个shopify_会话过滤器,用于处理OAuth,因此不确定我将如何更改它。使其正常工作,正在尝试使用该信息创建新操作。最好的方法是在会话控制器中编辑show操作。非常感谢。