5

I am trying to do something relatively simple.

I have a request that receives an oauth token (Bearer asdf22324...) I need it to pass it to my feign client to be able to request another service using the same token.

Is it possible to do that? Any ideas/examples?

I have tried this way:

@PostMapping("/login")
ResponseEntity<Void> loginUser(@RequestHeader("Authorization") String authHeader);

But authHeader is always empty...

I also tried the interceptor, but I'm not sure how it would affect others (and not sure how to invoke it either).

Feign Client - Dynamic Authorization Header

Ideas?

kyle
  • 691
  • 1
  • 7
  • 17
jpganz18
  • 5,508
  • 17
  • 66
  • 115

1 Answers1

7

May be you can try implementing the Filter (say TokenFilter) and inside it you can read the Authorization header from the HttpServletRequest and extract the token.

String authTokenHeader = request.getHeader("Authorization");

// parse the token
// there can be type of token passed. So you may need to take the substring after the type and the whitespace. Eg: Bearer <TOKEN>
the_tech_maddy
  • 575
  • 2
  • 6
  • 21
  • 1
    Please note that request.getHeader("Authorization") may not return only token string, but also the type of token at the beginning, something like: "Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSl..." – victory Mar 21 '20 at 16:39