OAuth 2.0-单资源服务器但多个客户端应用程序 [英] Oauth 2.0 - Single resource server but multiple client applications

查看:67
本文介绍了OAuth 2.0-单资源服务器但多个客户端应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候语,

我想问以下是不是OAuth 2.0的有效用例:

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

如果这是有效的用例,我们如何使用授权服务器配置多个客户端。无法使用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

这篇关于OAuth 2.0-单资源服务器但多个客户端应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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