具有隐式授权类型 Spring 启动应用程序的 OAuth 2.0
OAuth 2.0 with Implict Grant type Spring boot app
我们正在构建一个已确定以下技术规格的应用程序。
- Angular 4/5 [前端]
- SpringBoot 框架[后端]
- OAuth 2.0 [授权]
- MySQL [数据库]
Note : We ourselves are having Resource Server, Authorization Server
流量
我们为多个客户 [我们的客户] 提供单个实例应用程序,他们将拥有自己的用户。每个用户都会收到一封电子邮件,通过我们的应用程序为他们各自的客户授权一些东西。电子邮件 link 将包含 client_id、record_id 加密和编码。当用户点击 link 时,它应该转到 AuthServer,通过其 client_id 授权客户端,并将令牌传回给用户代理,以进行任何进一步的操作。
我们经历了这个 Github repo 并实现了与示例相同的方式。
AuthServerConfigure
代码如下:
@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");
}
我们对传递给配置方法的值有一些疑问。
- 这里的
.inMemory().withClient("my-trusted-client")
代表什么?这会一直被硬编码吗?由于我们将根据收到的 client_id 验证每个客户端,我们将把它提供给哪里以进行动态验证?
.withClient("my-client-with-registered-redirect")
有什么用?即使这对每个客户都保持不变?
- repo 中的作者还说我们可以通过以下方式验证设置
$ curl -H "Accept: application/json" my-client-with-secret:secret@localhost:8080/oauth/token -d grant_type=client_credentials
并且我看到 my-client-with-secret:secret
通过了这里。如果要针对不同的客户更改此值,我该如何将此值赋予 .withClient("my-client-with-secret")
和 .secret("secret")
我们很难理解这些概念。我们的要求很简单,我们将使用 client_id 验证每个客户端并为该客户端生成令牌 。对于此类要求,我们还需要其他 Grant_types
吗?
请有人指出正确的方向。
第一个问题:
在您的示例中,客户端是硬编码的(因此 clients.inMemory()
)。您可以配置数据源并使用它:
@Autowired
DataSource dataSource;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.jdbc(dataSource); // Get clients from database, table = oauth_client_details
}
您可以在 documentation
中找到更多信息
第二题例子中配置了三个客户端:
my-trusted-client
:此客户端可以授权使用这些 OAuth2 流程:"password", "authorization_code", "refresh_token", "implicit"
my-client-with-registered-redirect
:此客户端可以授权使用这些 OAuth2 流程:"authorization_code"
my-client-with-secret
:此客户端可以授权使用这些 OAuth2 流程:"client_credentials"
您需要了解这些流程之间的区别。
第三个问题如果要使用其他客户端,必须在code/database
中添加
我们正在构建一个已确定以下技术规格的应用程序。
- Angular 4/5 [前端]
- SpringBoot 框架[后端]
- OAuth 2.0 [授权]
- MySQL [数据库]
Note : We ourselves are having Resource Server, Authorization Server
流量
我们为多个客户 [我们的客户] 提供单个实例应用程序,他们将拥有自己的用户。每个用户都会收到一封电子邮件,通过我们的应用程序为他们各自的客户授权一些东西。电子邮件 link 将包含 client_id、record_id 加密和编码。当用户点击 link 时,它应该转到 AuthServer,通过其 client_id 授权客户端,并将令牌传回给用户代理,以进行任何进一步的操作。
我们经历了这个 Github repo 并实现了与示例相同的方式。
AuthServerConfigure
代码如下:
@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");
}
我们对传递给配置方法的值有一些疑问。
- 这里的
.inMemory().withClient("my-trusted-client")
代表什么?这会一直被硬编码吗?由于我们将根据收到的 client_id 验证每个客户端,我们将把它提供给哪里以进行动态验证? .withClient("my-client-with-registered-redirect")
有什么用?即使这对每个客户都保持不变?- repo 中的作者还说我们可以通过以下方式验证设置
$ curl -H "Accept: application/json" my-client-with-secret:secret@localhost:8080/oauth/token -d grant_type=client_credentials
并且我看到my-client-with-secret:secret
通过了这里。如果要针对不同的客户更改此值,我该如何将此值赋予.withClient("my-client-with-secret")
和.secret("secret")
我们很难理解这些概念。我们的要求很简单,我们将使用 client_id 验证每个客户端并为该客户端生成令牌 。对于此类要求,我们还需要其他 Grant_types
吗?
请有人指出正确的方向。
第一个问题:
在您的示例中,客户端是硬编码的(因此 clients.inMemory()
)。您可以配置数据源并使用它:
@Autowired
DataSource dataSource;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.jdbc(dataSource); // Get clients from database, table = oauth_client_details
}
您可以在 documentation
中找到更多信息第二题例子中配置了三个客户端:
my-trusted-client
:此客户端可以授权使用这些 OAuth2 流程:"password", "authorization_code", "refresh_token", "implicit"
my-client-with-registered-redirect
:此客户端可以授权使用这些 OAuth2 流程:"authorization_code"
my-client-with-secret
:此客户端可以授权使用这些 OAuth2 流程:"client_credentials"
您需要了解这些流程之间的区别。
第三个问题如果要使用其他客户端,必须在code/database
中添加