title: Oauth client with a Doorkeeper provider behind basic authentication
body: <p>We are setting up a Doorkeeper provider on our main app to enable Oauth2 authentication on some side applications. Everything's working fine on our production environement.</p>
  
  <p>On the staging environment that's another story, because our staging applications are behind basic authentication :</p>
  
  <pre><code>config.middleware.insert_after(::Rack::Runtime,
                                 'Rack::Auth::Basic',
                                 "Staging") do |user, password|
                                   [user, password] == [ENV['STAGING_USERNAME'], ENV['STAGING_PASSWORD']]
                                end
  end
  </code></pre>
  
  <p>Which means the Oauth endpoint must pass thru this Basic authentication. Here is the Oauth client configuration :</p>
  
  <pre><code>require 'omniauth-oauth2'
  
  module OmniAuth
    module Strategies
      class MyAuth &lt; OmniAuth::Strategies::OAuth2
        option :name, "MyAuth"
  
        # Added Basic auth credentials for staging environment
        option :client_options, {:site =&gt; "https://youshall:notpass@my-staging-server.info"}
  
        uid{ raw_info['id'] }
  
        info do
          {
            remote_id: raw_info['remote_id'],
            name: raw_info['name'],
            email: raw_info['email']
          }
        end
  
        extra do
          {
            'raw_info' =&gt; raw_info
          }
        end
  
        def raw_info
          @raw_info ||= access_token.get('/api/me').parsed
        end
      end
    end
  end
  </code></pre>
  
  <p>But Oauth seems not to be able to parse the URI including, as I get the following error when trying to get credentials :</p>
  
  <pre><code>Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8
  - 51 non-project frames
  1
  File "/app/vendor/bundle/ruby/2.4.0/gems/oauth2-1.2.0/lib/oauth2/error.rb" line 30 in encode
  2
  File "/app/vendor/bundle/ruby/2.4.0/gems/oauth2-1.2.0/lib/oauth2/error.rb" line 30 in error_message
  3
  File "/app/vendor/bundle/ruby/2.4.0/gems/oauth2-1.2.0/lib/oauth2/error.rb" line 17 in initialize
  4
  File "/app/vendor/bundle/ruby/2.4.0/gems/oauth2-1.2.0/lib/oauth2/client.rb" line 112 in new
  5
  File "/app/vendor/bundle/ruby/2.4.0/gems/oauth2-1.2.0/lib/oauth2/client.rb" line 112 in request
  6
  File "/app/vendor/bundle/ruby/2.4.0/gems/oauth2-1.2.0/lib/oauth2/client.rb" line 138 in get_token
  7
  File "/app/vendor/bundle/ruby/2.4.0/gems/oauth2-1.2.0/lib/oauth2/strategy/auth_code.rb" line 29 in get_token
  8
  File "/app/vendor/bundle/ruby/2.4.0/gems/omniauth-oauth2-1.4.0/lib/omniauth/strategies/oauth2.rb" line 89 in build_access_token
  9
  File "/app/vendor/bundle/ruby/2.4.0/gems/omniauth-oauth2-1.4.0/lib/omniauth/strategies/oauth2.rb" line 73 in callback_phase
  10
  File "/app/vendor/bundle/ruby/2.4.0/gems/omniauth-1.3.1/lib/omniauth/strategy.rb" line 227 in callback_call
  11
  File "/app/vendor/bundle/ruby/2.4.0/gems/omniauth-1.3.1/lib/omniauth/strategy.rb" line 184 in call!
  12
  File "/app/vendor/bundle/ruby/2.4.0/gems/omniauth-1.3.1/lib/omniauth/strategy.rb" line 164 in call
  13
  File "/app/vendor/bundle/ruby/2.4.0/gems/omniauth-1.3.1/lib/omniauth/builder.rb" line 63 in call
  </code></pre>
  
  <p>I couldn't find anyway to provide Basic auth credentials for Omniauth or Omniauth::Oauth2 if Oauth server is behind such authentication.</p>
  
  <p>Another way could be to whitelist IP address of staging clients on the staging Oauth server. As we are using Heroku, apps run on highly dynamic IP addresses. Some heroku addons allow to route outbound trafic through statig IPs BUT I need to programmatically setup a proxy. And I could not find the way to configure this proxy for Oauth requests.</p>
  
  <p>Anybody ran into such issue and found a workaround ?</p>