简体   繁体   中英

how can I get the current Bearer token of my request?

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?

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 technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM