【问题标题】:How to get userinfo by jwt token in spring security oauth2 authorization server?如何在spring security oauth2授权服务器中通过jwt令牌获取用户信息?
【发布时间】:2020-11-03 12:29:40
【问题描述】:

我通过 spring security oauth2 实现了一个 oauth2 授权服务器并使用JwtTokenStore 来存储访问令牌,然后我需要为当前访问令牌提供一个 /userinfo 控制器以通过 oauth2 客户端获取用户信息,/userinfo如下:

 @RequestMapping("/userinfo")
    public Object getCurrentUserInfo(HttpServletRequest request) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication;
    }

但我不知道如何获取用户信息?

【问题讨论】:

  • 一旦客户端进行身份验证,它将获得访问令牌,然后您需要在访问用户信息端点时将访问令牌包含在标头(授权承载 ....)中

标签: spring-security spring-security-oauth2


【解决方案1】:

也许需要阅读更多OAuth 2 Developers Guide。了解Authorization ServerResource ServerOAuth 2.0 Client 的功能,了解spring security

要通过访问令牌获取userinfo,也应在Authorization Server 中配置resource server。因为resource server 提供了一个过滤器OAuth2AuthenticationProcessingFilter 以通过令牌获取用户信息并设置为SecurityContextHolder

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-29
    • 2015-05-22
    • 2016-08-07
    • 2021-11-23
    • 2016-08-01
    • 2017-12-27
    • 2018-10-06
    • 2015-08-18
    相关资源
    最近更新 更多