Feign Oauth how to manually set the bearer token value?

4.4k views Asked by At

I'm developping a Rest API, MyApi. In there, I'm using Feign (and swagger codegen) to generate a client for another API, let's call it Ext-API.

The user will have called Ext-API previously and among other things will have retrieved a JWT Token. He'll then call my API using Basic Auth and in the body it'll give me the JWT token.

I'm to use this JWT token as auth header to connect to Ext-API from my API and do some more stuff on behalf of the user.

However all example of Oauth & Feign example rely on the Oauth also being used to connect to the API using the generated client.

I can't find how I could, on every request, update the Oauth Token. There are nothing exposed by feign to do this. Atm I'm using regular Rest template.

1

There are 1 answers

2
Musaddique S On

You can used @RequestHeader in feign Client, see below

@FeignClient(name = "<name>", configuration = <configclass>)
public interface Client {

    public final String AUTH_TOKEN = "Authorization";

    @RequestMapping(method = RequestMethod.GET, value = "users", produces = "application/json")
    public HttpEntity<List<User>> getUsers(@RequestHeader(AUTH_TOKEN) String oruToken,
            @RequestParam("<param>") Integer value);
}

and from you program you can pass token to feign client