Toji
Toji

Reputation: 250

How to propagate token using Spring Feign Client

I am using Feign Client to call another microservice as below:

@FeignClient("employee")
public interface EmployeeFeignClient {

    @RequestMapping(
        method= RequestMethod.GET,
        value="/employee/code/{code}",
        consumes="application/json"
    )
    EmployeeResponseEntity getEmployeeByCode(@PathVariable("code") String code);
}

The service which calls the employee service will have authentication bearer token in its request header. I need to pass this same token to the service call being made. Tried to find on how to achieve the same but could not. Some help would be nice.

Upvotes: 0

Views: 1292

Answers (1)

Sumit Dhyani
Sumit Dhyani

Reputation: 69

It was answered before.

The solution is to use @RequestHeader annotation instead of feign specific annotations

@FeignClient(name="Simple-Gateway")
interface GatewayClient {    
    @RequestMapping(method = RequestMethod.GET, value = "/gateway/test")
    String getSessionId(@RequestHeader("X-Auth-Token") String token);
}

Upvotes: 1

Related Questions