How to add a request interceptor to a feign client?

前端 未结 1 942
挽巷
挽巷 2021-02-05 12:24

I want every time when I make a request through feign client, to set a specific header with my authenticated user.

This is my filter from which I get the authentication

1条回答
  •  醉酒成梦
    2021-02-05 13:17

    You don't really need your own implementation of the FeignRequestInterceptor as there is already BasicAuthRequestInterceptor in the feign.auth package that does exactly the same.

    With this said, you basically have almost everything set up already. All is left to do is to define the basicAuthRequestInterceptor bean with specific username and password:

    @Bean
    public RequestInterceptor basicAuthRequestInterceptor() {
        return new BasicAuthRequestInterceptor("username", "password");
    }
    

    0 讨论(0)
提交回复
热议问题