Spring OAuth2在OAuth客户端获取用户详细信息 [英] Spring OAUTH2 fetch userdetails on oauth client
本文介绍了Spring OAuth2在OAuth客户端获取用户详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对Spring OAuth2相当陌生。我想知道是否可以在OAuth客户端附加自定义用户详细信息。
类似这样的
@EnableOAuth2Sso
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
@Qualifier("customUserDetailsService")
private UserDetailsService userDetailsService;
@Override
public void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/login**")
.permitAll()
.anyRequest()
.authenticated();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
}
}
这不起作用,因为配置以某种方式被忽略。
此客户端已成功在Spring OAuth2身份验证服务器中进行身份验证,但我希望在获得授权后加载其他用户详细信息。
推荐答案
UserDetailsService
的自定义实现用于在身份验证过程中按用户名加载用户,属于AuthorizationServerConfigurerAdapter
。我们覆盖其配置(..)方法,该方法以AuthorizationServerEndpointsConfigurer
作为参数并将其设置在那里。
ClientDetailsService
的自定义实现。在身份验证期间,这用于按客户端ID加载客户端。此自定义实现也以与UserDetailsService
相同的方式注册。
@Override
public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager);
endpoints.userDetailsService(userDetailsService);
endpoints.tokenStore(tokenStore);
endpoints.setClientDetailsService(clientDetailsService);
endpoints.accessTokenConverter(accessTokenConverter);
}
这篇关于Spring OAuth2在OAuth客户端获取用户详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文