Spring OAuth2.0 - 动态注册 OAuth2.0 客户端 [英] Spring OAuth2.0 - Dynamically register OAuth2.0 client

查看:91
本文介绍了Spring OAuth2.0 - 动态注册 OAuth2.0 客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on setting up an OAuth2.0 authorization server using Spring security. I want to know if there is a way to dynamically register an OAuth2.0 client after the OAuth2.0 authorization server is up and running?

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

Basically, I know that I can register a client while configuring the OAuth2.0 server by extending the AuthorizationServerConfigurerAdapter and overriding the configure method to add the client details in memory. However, this way the client is pre-registered and I would like to know how to dynamically add the client details.

<代码>@覆盖公共无效配置(ClientDetailsS​​erviceConfigurer 客户端)抛出异常 {//@格式化程序:关闭客户.inMemory().withClient(CLIENT_ID).secret(CLIENT_SECRET).authorizedGrantTypes("authorization_code", "隐式").redirectUris("http://junk/").scopes("cn").accessTokenValiditySeconds(600);//@格式化程序:打开}

推荐答案

你应该可以只使用JdbcClientDetails(甚至还有类似于内存中的方便方法):

You should be able to just use the JdbcClientDetails (there are even convenience methods similar to the in memory ones):

    @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.)然后你就有了一个包含数据的数据库,你可以在运行时随意更改.

(Code taken from here: https://github.com/spring-projects/spring-security-oauth/blob/master/tests/annotation/jdbc/src/main/java/demo/Application.java#L102.) Then you have a database with data you can change at runtime as much as you want.

这篇关于Spring OAuth2.0 - 动态注册 OAuth2.0 客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆