简体   繁体   English

Spring Oauth2客户端和用户凭证组合

[英]Spring Oauth2 client and user credentials combination

I am developing an app secured with Spring Oauth2, password flow. 我正在开发一个使用Spring Oauth2和password流保护的应用程序。

But I'm still confused about difference between UserDetailService and ClientDetailsService flows in Spring. 但是我仍然对Spring中UserDetailService和ClientDetailsS​​ervice流之间的差异感到困惑。

As I understand from OAuth2 specification, client and user are different entities. 据我从OAuth2规范了解,客户端和用户是不同的实体。 Client has clientId , clientSecret and some grants , and User has username , password and also some grants . 客户clientIdclientSecret和一些grants用户 clientSecret usernamepassword和一些grants

Multiple users use the same client (mobile app or web browser in my case). 多个用户使用同一个客户端(在我的情况下为移动应用或网络浏览器)。

So I need to authenticate some user and provide it with an access token. 因此,我需要验证一些用户并为其提供访问令牌。

I have implemented both UserDetailsService and ClientDetailsService (with all needed infrastructure: AuthorizationServerConfigurerAdapter and ResourceServerConfigurerAdapter) and during authentication I see, that username from request is passed as clientId into clientDetailsService and as username into userDetailsService. 我已经实现了UserDetailsServiceClientDetailsService (具有所有必需的基础结构:AuthorizationServerConfigurerAdapter和ResourceServerConfigurerAdapter),并且在身份验证期间,我看到请求中的用户名作为clientId传递给clientDetailsS​​ervice,并作为username传递给userDetailsS​​ervice。

But I thought it should be more complex process like for authentication request client should provide both client credentials and user credentials so then I can verify client (is it registered in my system) and its grants then verify user and its grants and then return an access token. 但是我认为这应该是一个更复杂的过程,例如对于身份验证请求,客户端应该同时提供客户端凭据和用户凭据,这样我才能验证客户端(它是否已在我的系统中注册)及其授权,然后验证用户及其授权,然后返回访问权限令牌。

My questions: 我的问题:

  1. Do I understand the process correctly? 我是否正确理解该过程?
  2. Are client grants and user grants of the same meaning? 客户赠款和用户赠款是否具有相同的含义?
  3. What classes should I customize to separate verification of client and user credentials? 我应该自定义哪些类以分开验证客户端和用户凭据?

Solution is stupid simple. 解决方案很愚蠢。

The client and the user are really different entities To obtain access token you need to complete basic authentication with Base64 encoded client credentials in header and username/password of the user in params . 客户端和用户实际上是不同的实体要获取访问令牌,您需要使用Base64 encoded client credentials在标头中以及username/password of the user in params完成基本身份验证。

Header pseudocode: 标头伪代码:

Basic Base64("client_id:client_secret")

Params: 参数:

username=username, password=password, grant_type=password

This will return you access_token, refresh_token and some extra info. 这将为您返回access_token,refresh_token和一些其他信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM