googleapis/signet

Faraday call fails behind a proxy

Closed this issue · 4 comments

Hello, I've just had the same issue, - the same code works fine out of proxy but fails if there is proxy.
Here is what the env command displays in the Terminal:

http_proxy=http://host-name.net:80
HTTP_PROXY=http://host-name.net:80
https_proxy=http://host-name.net:80
HTTPS_PROXY=http://host-name.net:80
no_proxy=127.0.0.1,localhost,10.1*.*.*,....some.others.sites.com
NO_PROXY=127.0.0.1,localhost,10.1*.*.*,som.others.sites.com

Here is the error I get when trying to access Google APIs:
IPAddr::InvalidAddressError (invalid address), see below function:

def auth_client
    Signet::OAuth2::Client.new(
      authorization_uri: 'https://accounts.google.com/o/oauth2/auth',
      token_credential_uri: 'https://www.googleapis.com/oauth2/v3/token',
      client_id: ENV['GOOGLE_KEY'], client_secret: ENV['GOOGLE_SECRET'],
      scope: 'email profile', redirect_uri: 'http://localhost:4200/oauth2callback'
    ).tap do |client|
      client.code = params['code']
      client.fetch_access_token!
    end
  end

The line that fails is:

client.fetch_access_token!

Here are my settings:

ruby 2.4.0
gem 'google-api-client', '~> 0.19.3'
gem 'jwt', '~> 2.1.0'
gem 'signet', '~> 0.8.1'
gem 'figaro', '~> 1.1.1'
rails '5.1.4'

If I unset the proxy setting, here is the error I have:

Faraday::ConnectionFailed (Failed to open TCP connection to www.googleapis.com:443 (No route to host - connect(2) for "www.googleapis.com" port 443)):

Any ideas on what is wrong here ? Thank you.

I think this issue might be useful for this, as it looks to have been a regression in faraday that has since been fixed.

lostisland/faraday#701

@belgoros Can you let us know what version of Faraday you were using? I believe proxy support was added to Faraday in 0.12.0, and this issue was fixed in 0.12.2.

@blowmage Unfortunately I have no more access to the code source of the app using signet (it was 11 months ago) and can't confirm the issue.
Anyway, trying just to run the below code behind a proxy:

require 'faraday'

con = Faraday.new(url: 'http://localhost:3000/ping')

response = con.get
puts "response.status: #{response.status}"
puts "headers: #{response.headers}"
puts response.body

works for faraday 0.13.1 and Ruby 2.5.0:

headers: {
	"content-type" => "application/json; charset=utf-8",
	"etag" => "W/\"0ddaf1eb16c9c39470a2dabe1cb4c8c0\"",
	"cache-control" => "max-age=0, private, must-revalidate",
	"x-request-id" => "c7f80da5-a3c3-41fb-9526-f1f56ac4a6fb",
	"x-runtime" => "0.240089",
	"vary" => "Origin",
	"connection" => "close",
	"transfer-encoding" => "chunked"
} {
	"pong": "OK"
}

Okay, thanks for checking. I’m pretty sure the issue is with faraday and not signet. Do you agree? If so, can we close this issue?