1. Add authorization header to Feign Client

In this short tutorial, we'll show you how to add Authorization header to Feign Client in Spring Cloud.

Since in Spring Cloud you usually have a lot of microservices, it's important to enable secure communication between those services - i.e. to be able to pass Authorization header from client request from one to another microservice. In this article we already explained how to achieve this using Rest Template.

Since in Feign Client you usually do everything in the interface, the same will be for the Authorization header. What you need to do is to simply pass your Authorization header in the declaration of your Feign Client method, as an @RequestHeader argument. 

This is the code sample where we're getting items by name and we're passing Authorization header from the caller service:

@FeignClient(name="someService")
public interface ItemFeignClientService {
@RequestMapping(method = RequestMethod.GET, value = "/items/search/findByName?name={name}")
List<Item> findItemsByName(@RequestHeader(value = "Authorization", required = true) String authorizationHeader, @PathVariable("name") String name);

2. Feign client logging

If you want to be sure that your header is there, you can log it - set that Feign Client logging level to full feign.client.config.default.loggerLevel = full, and you'll see the authorization header.