Proxy with Authentication #87
Comments
After coordinating with a couple people on this one, it appears that there's an underlying issue that I'm hoping may be addressable within the current version of scalaj. Because the endpoint beyond the proxy is HTTPS, my Proxy-Authorization header is being stripped on the initial CONNECT with the proxy server. Is there a way to modify the connection to ensure that the header stays put? |
hi, i'm not sure, could you send a code example for the request your making? also, a public authenticated proxy or explanation of how to create one would be helpful for me to reproduce |
You can set up a free trial at http://proxymesh.com/ which can give you some credentials and a proxy to connect. Steps to reproduce the problem (and code) are as follows:
|
I think you might need to set a global Authenticator to handle this. See this answer: http://stackoverflow.com/a/16340273 It's a bit gross to have to set a global like this, but let me know if this works. Maybe it can be baked into this library: import java.net.{Authenticator, PasswordAuthentication}
def setProxyCreds(proxyHost: String, proxyPort: Int, proxyUser: String, proxyPassword: String): Unit = {
Authenticator.setDefault(new Authenticator() {
override def getPasswordAuthentication(): PasswordAuthentication = {
if (getRequestorType() == Authenticator.RequestorType.PROXY) {
if (getRequestingHost().equalsIgnoreCase(proxyHost) && getRequestingPort() == proxyPort) {
new PasswordAuthentication(proxyUser, proxyPassword.toCharArray())
}
}
null
}
})
} |
I tried this very same solution and wasn't able to get it to work, unfortunately. I also tried setting the global Is it possible that scalaj doesn't use the default authenticator when initiating the connect? Were you able to successfully apply your solution? |
I haven't tested myself, but scalaj uses the HTTPURLConnection under the On Wed, Jan 20, 2016 at 3:06 PM, crockpotveggies notifications@github.com
|
Ran a few tests and can confirm that the Authenticator isn't being called. Does scalaj use its own classloader or anything else unrelated? |
No, it's not really doing any crazy tricks. The source is pretty On Wed, Jan 20, 2016 at 4:58 PM, crockpotveggies notifications@github.com
|
The nice folks at WonderProxy took a stab at the problem, and apparently had some results. The difference between their solution and my solution, is that they changed the default authenticator after instantiating an
My solution was doing the opposite. Any ideas why this seems to matter? |
No, I wouldn't think it would matter. Building the HttpRequest doesn't On Thu, Jan 21, 2016 at 11:15 AM, crockpotveggies notifications@github.com
|
Going to test this later today when I have the time, but I'm starting to wonder if this could have been at all affected by dependency injection. I'm going to have to think about our application architecture through the whole stack. |
Closing. plz re-open if there is still an issue. |
I still have this problem. I am using the code that suggested @crockpotveggies but i still recive this error: This is the code i used:
|
Does the equivalent curl command work for you? I don't have access to an authenticated proxy to test myself |
Also, going back the originally reported problem, I don't see the I even setup a lightweight proxy server using nginx to test out. And then executed this request to verify all the headers being passed along:
nginx.conf:
|
Yes, the curl command working for me. |
What OS and Java version are you using? |
OS: Linux dell 4.9.0-1-amd64 #1 SMP Debian 4.9.2-2 (2017-01-12) x86_64 GNU/Linux |
Hi, can you try cloning the source and running |
Failed 2 tests. This is the output of the 2 fails:
|
Sorry, a recent test code change I made was causing this failure on certain systems. I reverted that change. Could you pull the latest and try again? |
All the tests success now. |
Great, then the proxying should work from your system. Can you try this from the console:
I added a helper method to set the proxy-authorization header. |
Ok, thanks, i will test it as soon as i can today and give you a feedback. |
I made some tests and this are the results: This give me the Authentication error: Then i assume that https is not supported? I can navigate to this url from the browser and with curl without problems with http and https. |
Hi, |
yes, same thing, never made it to released version? |
The proxy thing doesn't work? Does someone have a solution. |
In build.sbt -: Tried this -: Unable to tunnel through proxy. Proxy returns "HTTP/1.0 407 Unauthorized" |
Hi @abhinavgazta -- can you try upgrading to version "2.4.1" and pass your proxy credentials using a new |
Hey, i did try with the new proxyAuth method, still same 407 issue. Doesn't work with it Http(goodUrl).proxyAuth("user", "pwd").proxy( Works with akka http using same proxy -: Not sure why its still not working with scalaj.http |
Also i think it might not be working for https proxies. HTTP might work. |
Yes, HTTPS proxies with authentication are not supported correctly due to the underlying reliance on the JDK's built-in http libraries. See here for detailed discussion on the fundamental problem and possible solution: https://stackoverflow.com/questions/34877470/basic-proxy-authentication-for-https-urls-returns-http-1-0-407-proxy-authenticat/34980074 I don't plan on fixing that at this time, but I would welcome a well tested PR |
It appears that scalaj may not support Proxies with authentication. After attempting to set a
Proxy-Authorization
header and passing an appropriate proxy config to the request object, I get the following error:The text was updated successfully, but these errors were encountered: