4

Within our microservices, we use Feign to communicate between services, we have a dedicated RequestInterceptor to handle the security and attach our JWT token to each request.

I would like to use Feign for calls to a 3rd party service outside my organization.

Let say my FeignClient looks like this.

@FeignClient(name = "ThirdPartyClient", url = "https://api.thirdparty.com/", configuration = ThirdPartyConfiguration.class)
public interface ThirdPartyClient { ... }

The problem is that this 3rd party client will also go through the list of RequestInterceptors and get the same authentication header used between my microservices. I would like to bypass the default list of RequestInterceptors to set a specific one.

I've tried to override the default config as described in the doc, I manage to add the specific RequestInterceptor but still goes through the list and so I get all headers in the request.

@Configuration
public class ThirdPartyConfiguration {

    @Bean
    public RequestInterceptor requestInterceptor() {
        return requestTemplate -> {
            requestTemplate.header("Authorization", "HEADER_VALUE");
        };
    }
}
Anthony Richir
  • 649
  • 2
  • 8
  • 31

1 Answers1

0

In the global RequestInterceptor, you can bypass authentication by checking for the feign client URL:

@Override
public void apply(RequestTemplate template) {
   if (template.url().equals("/your_specific_url")) {
            /*apply auth header*/
   }
}
untrue
  • 1
  • 2