I have a microservice project, I started using FeignClien in it. But there was a problem, if I logged in on one service and from this service I go to another, then on the other I also need to log in. The code for such an application can be found here. How to solve this problem?

    1 answer 1

    Suppose that authentication occurs by a token that is transmitted in the Authorization header , and the Authentication object is constructed in such a way that the token itself can be obtained by calling getDetails () . Then you need to add a bean of the feign.RequestInterceptor class to the configuration:

    @Bean RequestInterceptor feignRequestInterceptor(){ return requestTemplate -> requestTemplate.header( "Authorization", SecurityContextHolder .getContext() .getAuthentication() .getDetails() .toString() ); } 

    Similar question https://stackoverflow.com/questions/40262132/how-to-add-a-request-interceptor-to-a-feign-client