Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feign Client Dynamic Authorization Header

Tags:

feign

I have a service that gets http request with an authorization header. When processing the request, I want to use a Feign Client to query another service. The query to the other service should include the different authorization header.

like image 469
Govardhana krishnan B Avatar asked Oct 17 '25 18:10

Govardhana krishnan B


1 Answers

You simple pass your header as an argument and you declare your method in your interface accordingly. Please find snippet of code below.

And when you run your Feign client with logging level full (feign.client.config.default.loggerLevel=full), you'll see the authorization header (being an OAuth Bearer access token in my case).

Hopefully this helps.

All the best, Wim

@FeignClient(name="mde", url="${MDE.campaignServiceEndpoint}")
public interface CampaignClientService {
    @RequestMapping(method = RequestMethod.GET, value = "/useCases/search/findByName?name={name}")
    @Cacheable("placementUseCase")
    PlacementUseCase findUseCaseByName(@RequestHeader(value = "Authorization", required = true) String authorizationHeader, @PathVariable("name") String name);
like image 101
Wim Van den Brande Avatar answered Oct 22 '25 05:10

Wim Van den Brande



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!