Shopify - creating session for private app

2019-07-30 14:04发布

I am trying to create an app using RoR so I can test the ShopifyAPI. I am using a private App I created via the partner admin portal.

I tried to create a session using the password generated. The session seems to be valid.

login_controller:

    def index
    debugger
    sess = ShopifyAPI::Session.new('a75999989b7715f73ae5273497b9bfcb:9eb9f578d9fcfd753713e079@mante-hudson7934.myshopify.com', '9eb9f578d9fcfd753713e0795')
    sess.valid?
    session[:shopify] = sess        
      flash[:notice] = "Logged in"
      redirect_to return_address
      session[:return_to] = nil
  end

But when I try to get all the products (products = ShopifyAPI::Product.find(:all, :params => {:limit => 10})

I end up with a 500 error.

here is the debug trace I have:

    1: ShopifyAPI::Base.site = https://a75999989b7715f73ae5273497b9bfcb:9eb9f578d9fcfd753713e079596d4fbd@mante-hudson7934.myshopify.com/admin/
~/.rvm/gems/ruby-1.9.3-p194@rails328/gems/shopify_app-4.0.0/lib/shopify_app/login_protection.rb:9
ShopifyAPI::Base.clear_session

and in the browser I have a exception: "Connection reset by peer - SSL_connect"

Apparently there is a problem with my session...

Is there anything I am missing?

Thank you

--EDIT--

Actually I tried grabing the products via IRB and end up with a the same 500 Error as well: "Connection reset by peer - SSL_connect"

Not sure why I have this error?

Regis

标签: shopify
2条回答
贪生不怕死
2楼-- · 2019-07-30 14:37

I am indeed under ubuntu environement. I just tried under windows and it seems to work at least in IRB console. As You mentionned I may have a problem with Ubuntu and OpenSSL. I will investigate this lead. Thank you

-------EDIT------- I tried connecting to the API under mac OS X Lion but got the same error. Does anybody is having hard time to connect to the Shopify API? If it's related to openssl is there a way to goet around this?

Thank you

查看更多
beautiful°
3楼-- · 2019-07-30 14:40

Most likely, your client is trying to connect using TLS 1.2, one of the more recent SSL/TLS protocols used in HTTPS. Our load balancing hardware has a known problem with TLS 1.2, although we weren't aware of it until I independently stumbled upon this bug myself.

I've made the rest of the Operations team aware of this, and I expect we'll be fixing this as soon as possible. Until then, you can use

http.ssl_version = :TLSv1

to force Ruby to use TLS 1.0 instead. (Some clients may need to use :SSLv3 instead.)

Here's an example of how to apply this workaround to ActiveResource, the gem that the shopify_api gem uses internally:

require 'active_resource/connection'

class ActiveResource::Connection
  def apply_ssl_options_with_ssl_version(http)
    apply_ssl_options_without_ssl_version(http)

    http.ssl_version = @ssl_options[:ssl_version] if @ssl_options && @ssl_options[:ssl_version]

    http
  end

  alias_method_chain :apply_ssl_options, :ssl_version
end

Now you can use

ShopifyAPI::Base.ssl_options = {:ssl_version => :TLSv1}

(or :SSLv3 if necesssary) to work around the problem.

查看更多
登录 后发表回答