我正在尝试从 spring 安全应用程序中的 amazon cognito 获取我的自定义属性,而我正在为此苦苦挣扎
该应用程序已经通过 Jwt 进行身份验证,但我没有设法从登录用户那里获得更多信息......
有一些已知的方法可以从我的 JWT 或类似的东西中获取我的 cognito 自定义用户属性?
我的配置类看起来像这样:
@Override
public void configure(HttpSecurity http) throws Exception{
http
.authorizeRequests(expressionInterceptUrlRegistry -> expressionInterceptUrlRegistry.anyRequest().authenticated())
.oauth2ResourceServer().jwt();
}
我试图在我的 OncePerRequest 过滤器中获取一些用户信息,这里:
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
var principal = (JwtAuthenticationToken)SecurityContextHolder.getContext().getAuthentication();
String clientId = null;
String userId = null;
if (principal != null) {
[ADD SOME CODE TO GET COGNITO CUSTOM ATTRIBUTE]
clientId = ((Jwt) principal.getPrincipal()).getClaim("client_id").toString();
userId = principal.getName();
}
谢谢