java - Oauth 2.0 - 单个资源服务器但多个客户端应用程序

标签 java spring spring-boot oauth-2.0 spring-security-oauth2

问候,

我想问以下是否是 Oauth 2.0 的有效用例:

  1. 授权服务器(单独)
  2. 单个(或多个)资源服务器
  3. 多个客户端应用程序访问同一资源服务器。

Diagram for scenario in question

如果这是一个有效的用例,我们如何使用授权服务器配置多个客户端。无法使用 application.properties (application.yml) 进行配置。

security.oauth2.client.client-id=dummy
security.oauth2.client.client-secret=password

security:
  oauth2:
    resource:
      token-info-uri: http://localhost:8080/oauth/check_token
    client:
      client-id: dummy
      client-secret: password

在这种情况下,多客户端应用程序的正确配置是什么?

最佳答案

因此,如果您有多个客户端,您可以通过扩展 AuthorizationServerConfigurerAdapter 在 AuthorizationServer 中注册客户端详细信息

以下是如何在内存中注册客户详细信息的示例:

@EnableAuthorizationServer
@Configuration
public class AuthServerConfig extends AuthorizationServerConfigurerAdapter {
    private final AuthenticationManager authenticationManager;

    @Autowired
    public AuthServerConfig(AuthenticationManager authenticationManager) {
        this.authenticationManager = authenticationManager;
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                .withClient("egen")
                .secret("{noop}egensecret")
                .authorizedGrantTypes("authorization_code","refresh_token","password")
                .scopes("food_read","food_write")
            .and()
                .withClient("oauthclient")
                .secret("{noop}oauthclient-secret")
                .authorizedGrantTypes("client_credentials", "refresh_token")
                .authorities("ROLE_USER", "ROLE_OPERATOR")
                .scopes("food_read");
    }
///more code
}

有关更多详细信息,您可以查看我的 github 存储库:

https://github.com/Dovchiproeng/spring-cloud-security-oauth2-poc/blob/master/spring-cloud-secure-auth-server/src/main/java/com/egen/springcloudsecureauthserver/config/AuthServerConfig.java

关于java - Oauth 2.0 - 单个资源服务器但多个客户端应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53716247/

相关文章:

java - 蓝牙限制

java - 正则表达式确定文本中某个单词的出现次数是否不超过 n 次

java - 构建多个maven pom文件并登录到单个文件

java - 当通过sql过程发生表更新时更新spring缓存

java - Bean 属性 'xxx' 不可读或具有无效的 getter 方法 : Does the return type of the getter match the parameter type of the setter?

mysql - mysql中出现重复记录

java - 为什么 TextView(带有 ID)不自动保存它的状态?

java - Reactor/WebFlux 实现了一个响应式的 http 新闻自动收报机

spring-security - Spring Boot 1.4 : Principal must not be null exception

java - WebMvcTest 与真实服务实现