我正在使用 Spring security 设置 OAuth2.0 授权服务器。我想知道是否有办法在OAuth2.0授权服务器启动并运行后动态注册OAuth2.0客户端?
基本上,我知道我可以在配置 OAuth2.0 服务器时通过扩展来注册客户端AuthorizationServerConfigurerAdapter
并重写配置方法以在内存中添加客户端详细信息。但是,这样客户端是预先注册的,我想知道如何动态添加客户端详细信息。
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
// @formatter:off
clients.inMemory()
.withClient(CLIENT_ID)
.secret(CLIENT_SECRET)
.authorizedGrantTypes("authorization_code", "implicit")
.redirectUris("http://junk/")
.scopes("cn")
.accessTokenValiditySeconds(600);
// @formatter:on
}
您应该能够使用JdbcClientDetails
(甚至还有类似于内存中方法的便捷方法):
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.jdbc(dataSource)
.passwordEncoder(passwordEncoder)
.withClient("my-trusted-client")
... etc.
(代码取自这里:https://github.com/spring-projects/spring-security-oauth/blob/master/tests/annotation/jdbc/src/main/java/demo/Application.java#L102.) 然后您就拥有了一个数据库,其中的数据可以在运行时根据需要进行更改。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)