资源服务器认证获取扩展用户信息

2021-03-14  本文已影响0人  尼尔君

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {

        DefaultAccessTokenConverter defaultAccessTokenConverter=new DefaultAccessTokenConverter();
        defaultAccessTokenConverter.setUserTokenConverter(myUserAuthenticationConverter);


        endpoints

                //认证管理器

                .authenticationManager(authenticationManager)

                //授权码服务
                .authorizationCodeServices(authorizationCodeServices())
                .reuseRefreshTokens(true)
                //令牌管理服务
                .tokenServices(authorizationServerTokenServices())

                .accessTokenConverter(defaultAccessTokenConverter)
                .allowedTokenEndpointRequestMethods(HttpMethod.POST);


    }

Converter

@Service
public class MyUserAuthenticationConverter extends DefaultUserAuthenticationConverter {


    @Override
    public Map<String, ?> convertUserAuthentication(Authentication authentication) {
        Map<String, Object> response = new LinkedHashMap();
        response.put("user_name", authentication);
        return response;
    }
}

上一篇下一篇

猜你喜欢

热点阅读