+-
Spring OAuth2自定义TokenEnhancer 不生效

自定义的TokenEnhancer如下:

public class CustomTokenEnhancer implements TokenEnhancer {
    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken oAuth2AccessToken, OAuth2Authentication oAuth2Authentication) {
        if (oAuth2AccessToken instanceof DefaultOAuth2AccessToken) {
            DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken)oAuth2AccessToken;
            Map<String, Object> additionalInformation = new HashMap<>();
            additionalInformation.put("client_id", oAuth2Authentication.getOAuth2Request().getClientId());;
            // 获取用户名
            SystemUserDetail user = (SystemUserDetail)oAuth2Authentication.getPrincipal();
            additionalInformation.put("user_name", user.getUsername());
            additionalInformation.put("user_id", user.getId());
            token.setAdditionalInformation(additionalInformation);
            return token;
        }
        return oAuth2AccessToken;
    }
}

在AuthorizationServerConfigurerAdapter配置中如下

@Bean
    public TokenEnhancer customTokenEnhancer(){
        return new CustomTokenEnhancer();
    }
@Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
        endpoints.authenticationManager(authenticationManager)
                .userDetailsService(systemUserService)
                .tokenStore(tokenStore)
                .tokenEnhancer(customTokenEnhancer());
    }

但是返回的格式还是没有变还是这样