Proxy returns "HTTP/1.1 407 Proxy Auth Required"
- Dominant language
- Java
- Stars
- 276
- Forks
- 223
- PR merge metrics
- No merged PRs in 30d
Description
Hi, we use following code to connect to Salesforce using Partner API Java library (com.force.api.force-partner-api), and we tested tunneling through local proxy with proxy authentication (username and password).
I am using Fiddler Web Debugger to emulate proxy, having the proxy authentication credentials set to 1:1 (username: 1, password: 1).
When the following code runs it throws exception you can see below when trying to create Connection.
```
ConnectorConfig partnerConfig = new ConnectorConfig();
partnerConfig.setUsername(userName);
partnerConfig.setPassword(password);
partnerConfig.setAuthEndpoint("https://login.salesforce.com/services/Soap/u/32.0");
partnerConfig.setProxy("localhost", 8888);
partnerConfig.setProxyUsername("1");
partnerConfig.setProxyPassword("1");
partner = new PartnerConnection(partnerConfig);
```
Exception:
```
com.sforce.ws.ConnectionException: Failed to send request to https://login.salesforce.com/services/Soap/u/32.0
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:121)
at com.sforce.soap.partner.PartnerConnection.login(PartnerConnection.java:1349)
at com.sforce.soap.partner.PartnerConnection.(PartnerConnection.java:405)
...
Caused by: java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Auth Required"
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2083)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1281)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1256)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at com.sforce.ws.transport.JdkHttpTransport.connectRaw(JdkHttpTransport.java:136)
at com.sforce.ws.transport.JdkHttpTransport.connectLocal(JdkHttpTransport.java:100)
at com.sforce.ws.transport.JdkHttpTransport.connectLocal(JdkHttpTransport.java:95)
at com.sforce.ws.transport.JdkHttpTransport.connect(JdkHttpTransport.java:91)
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:95)
... 6 more
```
Note that the proxy authentication works otherwise, ie. when browsing the web it asks for credentials. Also when using just the proxy without authentication it works too. Only the proxy authentication doesn't work.
When I inspect the request using Fiddler I can see that the request doesn't have any auth headers as it should:
```
CONNECT login.salesforce.com:443 HTTP/1.1
User-Agent: Java/1.8.0_25
Host: login.salesforce.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Proxy-Connection: keep-alive
```
When I debug through the Partner API code I can see that it correctly sets the headers including the authentication headers (with value: Basic MTox, which is Base64 for "1:1"), in the class JdkHttpTransport, line 171:
```
if (config.getProxyUsername() != null) {
String token = config.getProxyUsername() + ":" + config.getProxyPassword();
String auth = "Basic " + new String(Base64.encode(token.getBytes()));
connection.addRequestProperty("Proxy-Authorization", auth);
connection.addRequestProperty("Https-Proxy-Authorization", auth);
}
```
However, magically the headers get lost and the request is send without them..
Does anyone know a solution to this? Thank you.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.