I'm trying to get SOCKS5 proxy working with authentication in OkHTTP.
Authentication works fine for HTTP proxies using the following code:
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("host", 1000));
Authenticator proxyAuthenticator = new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
String credential = Credentials.basic("username", "password");
return response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
}
};
client = defaultClient(key, timeout)
.newBuilder()
.proxyAuthenticator(proxyAuthenticator)
.proxy(proxy)
.build();
}
But when using Proxy.Type.SOCKS
it throws java.net.SocketException: SOCKS : authentication failed
.
I've found a few SO (1, 2) and GitHub answers on the topic but none have a working code example.