【发布时间】:2019-06-17 18:49:17
【问题描述】:
我已在令牌提供程序的 JWT 令牌中设置声明。现在我想在 API 被命中时通过身份验证获取声明值。
我已经检查了委托人、详细信息、凭据、权限,但我没有收到任何声明。
Claims claims = Jwts.claims().setSubject(authentication.getName());
claims.put(AUTHORITIES_KEY, authorities);
claims.put("userId", userRepo.findUserIdByUsername(authentication.getName()));
return Jwts.builder()
.setSubject(authentication.getName())
.setClaims(claims)
//.claim(AUTHORITIES_KEY, authorities)
.signWith(SignatureAlgorithm.HS512, SIGNING_KEY)
.setIssuedAt(new Date(System.currentTimeMillis()))
.setExpiration(new Date(System.currentTimeMillis() + ACCESS_TOKEN_VALIDITY_SECONDS*1000))
.compact();
我想通过身份验证或任何其他方式从令牌中获取“userId”声明。
【问题讨论】:
标签: java spring spring-boot spring-security jwt