0

Recently I'm using pac4j project for Oauth Twitter.Running on the local, everything works fine.But when I'm running on the remote server, unfortunately, the service doesn't work properly because there is no direct access to the external network.

For example,in apache.httpcomponents:httpclient:

HttpClients.custom().setSSLSocketFactory(sslsf).setProxy(new HttpHost("192.168.200.14", 8080)).build()

How to use HTTP Proxy with Pac4j-oauth?

2 Answers2

0

You should be able to do:

JDKHttpClientConfig myConfig = JDKHttpClientConfig.defaultConfig();

Proxy myProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("1.0.0.0", 8080));
myConfig.setProxy(myProxy);

twitterClient.getConfiguration().setHttpClientConfig(myConfig);
jleleu
  • 2,309
  • 1
  • 13
  • 9
0

OK.I had a new idea when I saw scribejava in github

pom.xml needs to be added:

<groupId>com.github.scribejava</groupId>
<artifactId>scribejava-httpclient-apache</artifactId>

code needs to be added:

//use Http Proxy
final HttpClientConfig clientConfig = new ApacheHttpClientConfig(HttpAsyncClientBuilder.create()
                .setProxy(new HttpHost("1.0.0.0", 8080)));
twitterClient.getConfiguration().setHttpClientConfig(clientConfig);

Finally worked fine when I tested with this scheme.