Omniauth + Google + Faraday + Behind the proxy = how setup proxy?

社会主义新天地 提交于 2019-12-06 05:28:01

I have solved problem by using monkey patching Oauth2.

require 'faraday'
module OAuth2
  # The OAuth2::Client class
  class Client 
    # The Faraday connection object
    def connection
        options[:connection_opts].merge!({:proxy => 'http://10.10.16.8:3128'})  
      @connection ||= begin
        conn = Faraday.new(site, options[:connection_opts])
        conn.build do |b|
          options[:connection_build].call(b)
        end if options[:connection_build]
        conn
      end
    end 
  end
end

Here is a better solution :

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_oauth2, 'login', 'password' {
    scope: ['userinfo.email'],
    access_type: 'online',
    client_options: {connection_opts: {proxy: 'http://myproxy:3128'}}
  }
end

Put in an initializer

 RestClient.proxy = "http://proxy.example.com/"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!