Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java OAuth 2.0和隐式授权类型Spring boot应用程序_Java_Spring Boot_Oauth 2.0_Spring Security Oauth2_Spring Security Rest - Fatal编程技术网

Java OAuth 2.0和隐式授权类型Spring boot应用程序

Java OAuth 2.0和隐式授权类型Spring boot应用程序,java,spring-boot,oauth-2.0,spring-security-oauth2,spring-security-rest,Java,Spring Boot,Oauth 2.0,Spring Security Oauth2,Spring Security Rest,我们正在构建一个具有以下技术规格的应用程序 角度4/5[前端] SpringBoot框架[后端] OAuth 2.0[授权] MySQL[数据库] 注意:我们自己有资源服务器、授权服务器 流量 我们为多个客户机[我们的客户机]提供了一个单实例应用程序,这些客户机将拥有自己的用户。每个用户都会收到一封电子邮件,通过我们的应用程序为他们各自的客户授权一些东西。电子邮件链接将包含加密和编码的客户端id、记录id。当用户单击链接时,它应该转到AuthServer,通过其客户端id授权客户端,并将令

我们正在构建一个具有以下技术规格的应用程序

  • 角度4/5[前端]
  • SpringBoot框架[后端]
  • OAuth 2.0[授权]
  • MySQL[数据库]
注意:我们自己有资源服务器、授权服务器


流量

我们为多个客户机[我们的客户机]提供了一个单实例应用程序,这些客户机将拥有自己的用户。每个用户都会收到一封电子邮件,通过我们的应用程序为他们各自的客户授权一些东西。电子邮件链接将包含加密和编码的客户端id、记录id。当用户单击链接时,它应该转到AuthServer,通过其客户端id授权客户端,并将令牌传递回用户代理,以进行任何进一步的操作

我们完成了这个并实现了与示例相同的功能

AuthServer
配置
代码如下:

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
       clients.inMemory().withClient("my-trusted-client")
             .authorizedGrantTypes("password", "authorization_code",
                            "refresh_token", "implicit")
             .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
             .scopes("read", "write", "trust").resourceIds("sparklr")
             .accessTokenValiditySeconds(60).and()
             .withClient("my-client-with-registered-redirect")
      .authorizedGrantTypes("authorization_code").authorities("ROLE_CLIENT")
             .scopes("read", "trust").resourceIds("sparklr")
             .redirectUris("http://anywhere?key=value").and()
             .withClient("my-client-with-secret")
             .authorizedGrantTypes("client_credentials", "password")
                    .authorities("ROLE_CLIENT").scopes("read").resourceIds("sparklr")
             .secret("secret");

}
我们对传递给configure方法的值有一些疑问

  • .inMemory().withClient(“我的可信客户机”)
    在这里代表什么?这是否总是硬编码的?由于我们将根据接收到的客户机id来验证每个客户机,我们将在何处对此进行动态验证
  • .withClient(“注册重定向的我的客户端”)
    用于什么?即使这对每个客户来说都保持不变
  • 回购协议的作者也说过,我们可以通过
    $curl-H“接受:应用程序/json”我的客户机密码:secret@localhost:8080/oauth/token-d grant\u type=client\u凭证
    我看到
    我的客户机在这里传递了secret:secret
    。如果要为不同的客户端更改此值,我如何将此值赋给
    .withClient(“我的客户端有密码”)
    .secret(“密码”)
我们很难理解这些概念。我们的要求很简单,我们将使用客户机id验证每个客户机,并为该客户机生成一个令牌。对于这种类型的需求,我们是否需要任何其他的
授权类型


请有人给我们指出正确的方向。

第一个问题: 在您的示例中,客户端是硬编码的(因此是
clients.inMemory()
)。您可以配置数据源并使用它:

@Autowired
DataSource dataSource;

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.jdbc(dataSource); // Get clients from database, table = oauth_client_details
}
您可以在中找到更多信息

第二个问题在示例中,配置了三个客户端:

  • my trusted client
    :此客户端可以使用以下OAuth2流进行授权:
    “密码”、“授权码”、“刷新令牌”、“隐式”
  • my client with registered redirect
    :此客户端可以使用这些OAuth2流进行授权:
    “授权\u代码”
  • my client with secret
    :此客户端可以授权使用这些OAuth2流:
    “客户端凭据”
  • 您需要了解这些流之间的区别


    第三个问题如果您想使用其他客户端,必须将它们添加到代码/数据库中

    非常感谢。。它消除了大部分疑虑……:)