Spring Oauth2 客户端和用户凭据组合
Spring Oauth2 client and user credentials combination
我正在开发一个使用 Spring Oauth2,password
流程保护的应用程序。
但我仍然对 Spring 中 UserDetailService 和 ClientDetailsService 流程之间的区别感到困惑。
据我了解,从 OAuth2 规范中,客户端和用户是不同的实体。 Client 有 clientId
、clientSecret
和一些 grants
,User 有 username
, password
还有一些 grants
.
多个用户使用同一个客户端(在我的例子中是移动应用程序或网络浏览器)。
所以我需要对一些用户进行身份验证并为其提供访问令牌。
我已经实现了 UserDetailsService
和 ClientDetailsService
(具有所有需要的基础设施:AuthorizationServerConfigurerAdapter 和 ResourceServerConfigurerAdapter),我看到在身份验证期间,来自请求的用户名作为 clientId
传递到 clientDetailsService和
作为 username
进入 userDetailsService。
但我认为它应该是更复杂的过程,比如身份验证请求客户端应该同时提供客户端凭据和用户凭据,这样我就可以验证客户端(它是否在我的系统中注册)及其授权,然后验证用户及其授权然后 return 一个访问令牌。
我的问题:
- 我对流程的理解是否正确?
- client grants 和 user grants 是同一个意思吗?
- 我应该自定义什么 类 来单独验证客户端和用户凭据?
解决方法很简单。
客户端和用户真的是不同的实体
要获得访问令牌,您需要在 header 和 username/password of the user in params
.
中使用 Base64 encoded client credentials
完成基本身份验证
Header伪代码:
Basic Base64("client_id:client_secret")
参数:
username=username, password=password, grant_type=password
这将为您 return access_token、refresh_token 和一些额外信息。
我正在开发一个使用 Spring Oauth2,password
流程保护的应用程序。
但我仍然对 Spring 中 UserDetailService 和 ClientDetailsService 流程之间的区别感到困惑。
据我了解,从 OAuth2 规范中,客户端和用户是不同的实体。 Client 有 clientId
、clientSecret
和一些 grants
,User 有 username
, password
还有一些 grants
.
多个用户使用同一个客户端(在我的例子中是移动应用程序或网络浏览器)。
所以我需要对一些用户进行身份验证并为其提供访问令牌。
我已经实现了 UserDetailsService
和 ClientDetailsService
(具有所有需要的基础设施:AuthorizationServerConfigurerAdapter 和 ResourceServerConfigurerAdapter),我看到在身份验证期间,来自请求的用户名作为 clientId
传递到 clientDetailsService和
作为 username
进入 userDetailsService。
但我认为它应该是更复杂的过程,比如身份验证请求客户端应该同时提供客户端凭据和用户凭据,这样我就可以验证客户端(它是否在我的系统中注册)及其授权,然后验证用户及其授权然后 return 一个访问令牌。
我的问题:
- 我对流程的理解是否正确?
- client grants 和 user grants 是同一个意思吗?
- 我应该自定义什么 类 来单独验证客户端和用户凭据?
解决方法很简单。
客户端和用户真的是不同的实体
要获得访问令牌,您需要在 header 和 username/password of the user in params
.
Base64 encoded client credentials
完成基本身份验证
Header伪代码:
Basic Base64("client_id:client_secret")
参数:
username=username, password=password, grant_type=password
这将为您 return access_token、refresh_token 和一些额外信息。