Faraday :: ConnectionFailed(已到达文件末尾)

And*_*nch 6 ssl https ruby-on-rails faraday

我正在使用Oauth2 Gem连接到服务。

我可以收到授权代码,但是当我使用该代码检索用户令牌时,会得到Faraday :: ConnectionFailed(到达文件末尾):

其他大多数问题都归因于过时的证书。但是,当我部署到Heroku时,此错误仍然存​​在。

client = OAuth2::Client.new(client_id, client_secret, :site => 'https://auth.mxit.com', :authorize_url => '/authorize', :token_url => '/token')

auth_code1 = client.auth_code.authorize_url(:redirect_uri => root_url+'oauth2/callback', :scope => 'message/send')

auth_code1 =params[:code]

base_code = Base64.encode64(client_id+' : '+client_secret)

token = client.auth_code.get_token(auth_code1, :redirect_uri => root_url+'oauth2', :grant_type =>'authorization_code', :headers => {'Content-Type' => 'application/x-www-form-urlencoded','Authorization' => 'Basic'+base_code })
Run Code Online (Sandbox Code Playgroud)

Ghi*_*his 0

不确定这是否有效,但我读到问题可能来自Accept-Encoding未设置请求标头(必须设置为identity)。尝试这个 :

token = client.auth_code.get_token(auth_code1,
  redirect_uri: root_url + 'oauth2',
  grant_type: 'authorization_code',
  headers: {
    'Content-Type' => 'application/x-www-form-urlencoded',
    'Authorization' => 'Basic' + base_code,
    'Accept-Encoding' => 'identity' # here
  }
)
Run Code Online (Sandbox Code Playgroud)