Spring OAuth2.0 - 动态注册OAuth2.0客户端

sun*_*985 3 spring spring-security spring-oauth2 oauth2

我正在使用Spring安全性设置OAuth2.0授权服务器.我想知道在OAuth2.0授权服务器启动并运行后是否有办法动态注册OAuth2.0客户端?

基本上,我知道我可以在配置OAuth2.0服务器时通过扩展AuthorizationServerConfigurerAdapter和覆盖configure方法来注册客户端,以在内存中添加客户端详细信息.但是,这种方式客户端已预先注册,我想知道如何动态添加客户端详细信息.

@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 }

Dav*_*yer 5

你应该能够使用JdbcClientDetails(甚至有类似于内存中的方便方法):

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.jdbc(dataSource)
                .passwordEncoder(passwordEncoder)
            .withClient("my-trusted-client")
        ... etc.
Run Code Online (Sandbox Code Playgroud)

(代码取自此处:https://github.com/spring-projects/spring-security-oauth/blob/master/tests/annotation/jdbc/src/main/java/demo/Application.java#L102.)然后你有一个数据库,你可以在运行时根据需要更改数据.