@Bean
public TokenEnhancer tokenEnhancer() {
return new TokenEnhancer() {
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken oAuth2AccessToken, OAuth2Authentication oAuth2Authentication) {
DefaultOAuth2AccessToken newToken = new DefaultOAuth2AccessToken(oAuth2AccessToken);
Map<String, Object> addInfo = new HashMap<>();
// add here what u need
addInfo.put("putName", oAuth2Authentication.getName());
newToken.setAdditionalInformation(addInfo);
return newToken;
}
};
}
,並在AuthorizationServerConfiguration:
@Autowired
private TokenEnhancer tokenEnhancer;
...
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
throws Exception {
endpoints
.tokenStore(this.tokenStore)
.authenticationManager(this.authenticationManager)
.userDetailsService(this.userDetailsService)
.tokenEnhancer(this.tokenEnhancer);
}
謝謝你的答案。我的想法是,服務器(終點)解碼訪問令牌,並與USER_ID的幫助下將用戶添加到SecurityContextHolder的 – jack 2014-09-21 12:07:33
檢查訪問令牌表的SQL它包含已經USER_NAME這樣你就可以從數據庫直接,明白了沒有需要解碼它。如果你的終端有這個數據庫不能訪問,可以auth服務器暴露基於訪問令牌的用戶配置文件,該請求由OAuth的固定上也做的端點。 – 2014-09-22 14:47:16