On the server side, how can springcloud tell whether the client that invokes the request is feign or browser?

to achieve permission verification, before using springcloud, the filter requested by http is verified according to the permission of token. After token
is added to the springcloud at the front end, the micro service is called with feign, but it is actually a http request. I don"t want to write the token parameter in every feign method, which is too troublesome. But without token, you can"t pass the original permission verification. There are several possible solutions:
1. The filter on the server distinguishes whether the client is feign or the front-end browser, but it is not authenticated if it is feign.
2.feign can set the parameters passed by global default, and you can add some parameters to let the server identify feign, without adding such code to every feign interface code

.
Jul.09,2021

ask and answer yourself, which can be implemented with the feign interceptor, adding the following classes anywhere

/**
 * feign
 * feignfeign
 */
@Configuration
public class FeignRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        //feign

    
        requestTemplate.header("msClientId", "8888");
    }
}

this kind of request will also be intercepted by ordinary requests. There is no way to tell if it is an feign request.

Menu