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

问题描述 投票:0回答:2

我正在使用 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
        }

spring spring-security oauth-2.0 spring-oauth2
2个回答
5
投票

您应该能够只使用

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 .) 然后你就有了一个数据库,其中的数据可以在运行时根据需要进行更改。


0
投票

您可以使用 spring 文档中的注册器配置并实现您的解决方案。

https://docs.spring.io/spring-authorization-server/reference/guides/how-to-dynamic-client-registration.html

© www.soinside.com 2019 - 2024. All rights reserved.