Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to configure feign.RequestInterceptor specific to a given feign client #288

Closed
xyloman opened this issue Mar 31, 2015 · 18 comments
Closed
Assignees
Labels
Milestone

Comments

@xyloman
Copy link

@xyloman xyloman commented Mar 31, 2015

There is a few use cases where we need to add different headers or authentication mechanisms on a per client basis. Currently the FeignClientFactoryBean appears to apply its configuration to all feign clients that it constructs. This was problematic in that some services that we want to use feign for require a different set of RequestInterceptors to one set of clients verse another. Is there a way to accomplish this today? We were able to work around this issue by using the feign builder directly, with the only thing we are customizing is the list RequestInterceptor from the other FeignClients.

@spencergibb

This comment has been minimized.

Copy link
Member

@spencergibb spencergibb commented Mar 31, 2015

Good idea. We have a similar mechanism for @RibbonClient we could reuse.

@sleepiejohn

This comment has been minimized.

Copy link

@sleepiejohn sleepiejohn commented Apr 7, 2015

Maybe we could register the RequestInterceptors through a value in @RibbonClient ? So it's clear which client use which interceptor

@spencergibb

This comment has been minimized.

Copy link
Member

@spencergibb spencergibb commented Apr 7, 2015

@joaoevangelista we need to maintain separation between Feign and Ribbon. I'm imagining the same type of facility that @RibbonClient uses for @FeignClient. We could probably generalize it for use with other annotations.

@sleepiejohn

This comment has been minimized.

Copy link

@sleepiejohn sleepiejohn commented Apr 7, 2015

@spencergibb Really sorry! I meant @FeignClient, I got confused a bit, but yea, a generalized way would be nice too

@marcosbarbero

This comment has been minimized.

Copy link
Contributor

@marcosbarbero marcosbarbero commented May 20, 2015

Hi everybody, how is this issue going?

@dwelch2344

This comment has been minimized.

Copy link

@dwelch2344 dwelch2344 commented Jul 8, 2015

Just wanted to throw in my vote on this. We've got a mixture of some ribbon backed FeignClients and a few that are hard coded to 3rd party APIs, so this would be a major win.

@spencergibb

This comment has been minimized.

Copy link
Member

@spencergibb spencergibb commented Jul 10, 2015

Yeah, I see this as our biggest feature for feign. I'm working on getting ready for a conference week after next, so it might not get started until after OSCON.

@sbuettner

This comment has been minimized.

Copy link

@sbuettner sbuettner commented Aug 7, 2015

Same as @dwelch2344. Would really like to see support for that. Maybe by leveraging springs @qualifier annotation.

@lpborges

This comment has been minimized.

Copy link

@lpborges lpborges commented Aug 20, 2015

This is exactly what I need.
I need to setup a FeignClient that use Basic Authentication, and this feature can help to setup a Feign BasicAuthRequestInterceptor different for each client.
Maybe some options for authentication on the FeignClient annotation can help too.

I figured to setup Authentication using headers in the RequestMapping:

@FeignClient(url="${service.url}")
public interface ProductsClient {

    @RequestMapping(method = RequestMethod.GET, value = "/item/{idProduct}", consumes = "application/json",
            headers="Authorization: Basic ${service.auth}")
    public ProductDTO getProduct(@PathVariable("idProduct") long idProduct);
}

But the problem is that the headers parameter don't apply the Spring value properties ( ${service.auth} ), so you need to hard code the authentication value.

@sleepiejohn

This comment has been minimized.

Copy link

@sleepiejohn sleepiejohn commented Aug 20, 2015

For now, you can create a bean of feign.RequestInterceptor returning a BasicAuthRequestInterceptor or implement your own, like I did for OAuth2 here. It will be applied to all requests using feign

@lpborges

This comment has been minimized.

Copy link

@lpborges lpborges commented Aug 21, 2015

Yes, but the problem is that the same Interceptor is used for all FeignClient, and I have 3 differents clients each one with different authentication user and password.

@dsyer dsyer added this to the 1.1.0 milestone Sep 8, 2015
@spencergibb spencergibb self-assigned this Oct 2, 2015
spencergibb added a commit that referenced this issue Oct 2, 2015
Similar to @RibbonClient

fixes gh-288
@spencergibb

This comment has been minimized.

Copy link
Member

@spencergibb spencergibb commented Oct 2, 2015

@xyloman @lpborges @joaoevangelista @marcosbarbero @dwelch2344 @sbuettner I have submitted PR #572 for review.

jkschneider added a commit to jkschneider/spring-cloud-netflix that referenced this issue Oct 8, 2015
@sbuettner

This comment has been minimized.

Copy link

@sbuettner sbuettner commented Nov 6, 2015

I think there is still an issue. It seems that RequestInterceptors are currently only retrieved from the application context but not from the @Configuration defined in the @FeignClient configuration property.

@spencergibb

This comment has been minimized.

Copy link
Member

@spencergibb spencergibb commented Nov 6, 2015

@sbuettner If you think there's an issue with the new functionality, please open a new issue, don't comment on an old one.

@choelea

This comment has been minimized.

Copy link

@choelea choelea commented Sep 28, 2016

One page helped me here is: http://stackoverflow.com/questions/37066331/using-headers-with-dynamic-values-in-feign-client-spring-cloud-brixton-rc2. Even though RequestInterceptor works fine for me but it's hard to set the header dynamically. I
I am using spring boot 1.4.0

@subodhkarwa

This comment has been minimized.

Copy link

@subodhkarwa subodhkarwa commented Apr 8, 2019

Is there any inbuild solution, if parameters in headers differ based on URL.
Let's say, one client only expects - autheticationToken while other excepts token along with "someSectetKey"

I am overriding interceptors but would welcome if there is something else which can support this

@ryanjbaxter

This comment has been minimized.

Copy link
Contributor

@ryanjbaxter ryanjbaxter commented Apr 11, 2019

@subodhkarwa not sure I understand your question. In any case please open an issue in the Open Feign project https://github.com/spring-cloud/spring-cloud-openfeign

@damianw345

This comment has been minimized.

Copy link

@damianw345 damianw345 commented Aug 7, 2019

Hello I found a way to configure two independent interceptors on two different feign clients. I just specified two configuration classes without spring @configuration annotation. So I have:
`
@RequiredArgsConstructor
public class FeignOauthClientConfiguration {

private final UploadConfiguration uploadConfiguration;
private final AuthorizationHeaderService authorizationHeaderService;

@Bean
public JiraOauthFeignClientInterceptor jiraOauthFeignClientInterceptor() {
    return new JiraOauthFeignClientInterceptor(uploadConfiguration, authorizationHeaderService);
}

}
`

and

`
public class FeignBasicAuthClientConfiguration {

@Value("${jira.user}")
private String user;

@Value("${jira.password}")
private String password;

@Bean
public RequestInterceptor basicAuthFeignClientInterceptor() {
    return new BasicAuthRequestInterceptor(user, password);
}

}
`
With @configuration annotation two interceptors were applied. It is connected to @bean Lite Mode

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/Bean.html

Configuration classes are then specified in @FeignClient configuration property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.