-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set up proxy credentials? #478
Comments
Although I have not done it myself, I would have expected that to work. You can see how we are creating the GeoIP2-java/src/main/java/com/maxmind/geoip2/WebServiceClient.java Lines 143 to 147 in cd77286
|
Hi @oschwald . The only way I could make the proxy correctly authenticated was by changing WebServiceClient to receive the authenticator in its Builder: Authenticator authenticator = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
if (getRequestorType() == RequestorType.PROXY) {
return new PasswordAuthentication("proxyUsername", "proxyPassword".toCharArray());
}
return null;
}
}
new WebServiceClient.Builder(42, "license_key")
.authenticator(authenticator)
.build(); However, because the authenticator returns null for non-proxy requests, the API call has the authentication header set by WebServiceClient cleared, resulting in an API authentication error. The version below works with the API credentials duplicated by the authenticator. Authenticator authenticator = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
if (getRequestorType() == RequestorType.PROXY) {
return new PasswordAuthentication("proxyUsername", "proxyPassword".toCharArray());
}
return PasswordAuthentication(42, "license_key".toCharArray());;
}
}
new WebServiceClient.Builder(42, "license_key")
.authenticator(authenticator)
.build(); The Javadoc for Authenticatior#setDefault says that the default authenticator is used if the "HTTP server asks for authentication", and I think that the MaxMind API server is not asking for HTTP authentication, so that's why the default authenticator should have been ignored. Open this URL below for example in the browser and it will pop up the authentication form because the server returns the www-authenticate header: The MaxMind API server doesn't return this header, making the web browser not to request credentials: See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate If the API would be changed to return this header it can still make sense to change its Java client library so that the API credentials do not have to be sent in two places. I changed the application I'm working on to use the REST API instead of the Java library so that it has better control over the proxy and API credentials being sent. |
The For instance, a request with
That said, I don't think we would want the client to issue a request that returned the header on a 401 and then have to make another round trip with the |
Thanks @oschwald . Indeed, the specific endpoint (https://geoip.maxmind.com/geoip/v2.1/country/{ip}) that I was trying to call with the client library is returning the header, so I don't know why the default authenticator is not taken into consideration by the library and I'm not sure there's a way to authenticate the proxy. |
Hi.
I'm using the library to call but the company I work for has a proxy that requires credentials.
How do I set up the credentials?
I already set up the default ProxySelector, which the library is using:
I also set up the default Authenticator, but its method is not executed when I try to interact with the API using the library methods, which results in HTTP error 407 Proxy Authentication Required:
Thanks for your attention.
The text was updated successfully, but these errors were encountered: