我正在尝试做一些相对简单的事情。我有一个接收 oauth 令牌的请求,(Bearer asdf22324...)我需要将其传递给我的 feign 客户端,以便能够使用相同的令牌请求另一个服务。有可能这样做吗?有什么想法/例子吗?我试过这样:@PostMapping("/login")
ResponseEntity<Void> loginUser(@RequestHeader("Authorization") String authHeader);但是 authHeader 总是空的......我也尝试了拦截器,但我不确定它会如何影响其他人(也不知道如何调用它)。Feign Client - 动态授权标头想法?
1 回答

冉冉说
TA贡献1877条经验 获得超1个赞
也许您可以尝试实现Filter(say TokenFilter) 并在其中读取Authorization标头HttpServletRequest并提取令牌。
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>
添加回答
举报
0/150
提交
取消