I am inserting an authorization header in a feign request but upon a 401 from the server I am retrying with the same request and same header, resulting in the same error. If I expire manually the token then I end up with 2 Authorization headers old and new resulting in a 400 error. So far I don't see any way of removing the old header and as far as I got was something like this:
@Bean
public RequestInterceptor oauth2ApplicationRequestInterceptor() {
return new OAuth2FeignRequestInterceptor(getOAuth2ClientContext(), oauth2ApplicationResourceDetails()) {
@Override
public void apply(RequestTemplate template) {
if (template.headers().containsKey("Authorization")) {
// if Authorization exists then remove it
} else {
super.apply(template);
}
}
};
Expiring manually the token is the only way for me at the moment if server gives me a 401 error.