我正在使用 Spring security 设置 OAuth2.0 授权服务器。我想知道是否有办法在OAuth2.0授权服务器启动并运行后动态注册OAuth2.0客户端?
基本上,我知道我可以在配置 OAuth2.0 服务器时注册客户端,方法是扩展 AuthorizationServerConfigurerAdapter
并重写配置方法以在内存中添加客户端详细信息。但是,这样客户端是预先注册的,我想知道如何动态添加客户端详细信息。
@覆盖
公共(public)无效配置(ClientDetailsServiceConfigurer客户端)抛出异常{
//@formatter:关闭
client.inMemory()
.withClient(CLIENT_ID)
.secret(CLIENT_SECRET)
.authorizedGrantTypes("authorization_code", "隐式")
.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。)然后您就有了一个数据库,其中的数据可以在运行时根据需要进行更改。
关于Spring OAuth2.0 - 动态注册OAuth2.0客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38595878/