【发布时间】:2021-08-26 21:32:27
【问题描述】:
我使用 springboot 并使用 oath2 (JWT)。 我的令牌是下一个
我想从控制器或过滤器中获取有效负载,但我不知道如何。
我尝试了这个,但它不起作用
@GetMapping("/user")
public String getB(@AuthenticationPrincipal Jwt principal, @RequestHeader("refresh") String refresh) {
System.out.println(principal.getClaims());;
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Object details = authentication.getDetails();
if ( details instanceof OAuth2AuthenticationDetails ){
OAuth2AuthenticationDetails oAuth2AuthenticationDetails = (OAuth2AuthenticationDetails)details;
Map<String, Object> decodedDetails = (Map<String, Object>)oAuth2AuthenticationDetails.getDecodedDetails();
System.out.println( decodedDetails.get("time_created") );
}
【问题讨论】:
-
你有 Jwt 对象作为输入,这是你应该使用的东西,但你没有使用它。
-
是的,亚历山德罗,谢谢
标签: java spring-boot oauth-2.0 controller jwt