marting
marting

Reputation: 175

Spring Boot Feign client proxy authentication

I have the following in my feign configuration class:

    @Bean
    public Client feignClient() {
        return new Client.Proxied(null, null,
                new Proxy(Proxy.Type.HTTP,
                        new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort))),
                        proxyUsername, proxyPassword);
    }

But it doesn't authenticate. It does work with OkHttpClient though, so I believe the username and password are ok. Can you say what is missing?

Upvotes: 2

Views: 2092

Answers (1)

Pavanraotk
Pavanraotk

Reputation: 1147

You can do it like this, this uses apache http5:

@Bean
public Client feignClient() {
    BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
    basicCredentialsProvider.setCredentials(new AuthScope(proxyHost, Integer.parseInt(proxyPort)),
    new UsernamePasswordCredentials(proxyUsername, proxyPassword));
    return new ApacheHttp5Client(HttpClients.custom()
         .setDefaultCredentialsProvider(basicCredentialsProvider)
         .setProxy(new HttpHost(proxyHost, Integer.parseInt(proxyPort)))
         .build());
}

Upvotes: 0

Related Questions