简体   繁体   中英

How to use HTTP Proxy with Pac4j-oauth?

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?

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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM