简体   繁体   English

使用 Spring oAuth2 impl,是否可以在刷新令牌授予期间“降级”访问令牌的范围?

[英]Using Spring oAuth2 impl, is it possible to "downgrade" the scopes of an access token during a refresh-token grant?

I have two clients, one Public Client used by regular end-users logging in via our web page or native apps and one Confidential Client for our admin system.我有两个客户端,一个是通过我们的网页或本机应用程序登录的普通最终用户使用的公共客户端,另一个是用于我们的管理系统的机密客户端。 Both issues two JWT's, one Access Token and one Refresh Token.两者都发出两个 JWT,一个访问令牌和一个刷新令牌。

The Public Client is not allowed to issue admin rights.不允许公共客户端颁发管理员权限。 The Access Token is short lived, and the Refresh Token has infinite life span.访问令牌是短暂的,而刷新令牌的寿命是无限的。

The Confidential Client is allowed to issue admin scopes.机密客户可以发布管理范围。 The Access Token is short lived, and the Refresh Token lives 24 hrs.访问令牌的生命周期很短,刷新令牌的生命周期为 24 小时。

Is it possible, using Spring Security and their oAuth2 implementation, to downgrade the admin user once the refresh token is expired?一旦刷新令牌过期,是否可以使用 Spring Security 及其 oAuth2 实现降级管理员用户? That is, once the user have been logged in for 24hrs, the user is not totally logged out, but on the next login he gets two new JWT's, one Access Token for regular user access and one matching Refresh Token for that access level.也就是说,一旦用户登录 24 小时,用户就不会完全退出,但在下次登录时,他会获得两个新的 JWT,一个用于常规用户访问的访问令牌和一个用于该访问级别的匹配刷新令牌。 I guess I'm looking for some kind of hook in the Spring Security framework that allows me to handle token expiration in a customised way.我想我正在 Spring Security 框架中寻找某种钩子,它允许我以自定义的方式处理令牌过期。

There's a sentence on your question that confuses me a bit, but I wanted to elaborate on other aspects so this did not fit in a comment.关于你的问题有一句话让我有点困惑,但我想详细说明其他方面,所以这不适合发表评论。

... the user is not totally logged out, but on the next login he gets two new JWT's, one Access Token for regular user access and one matching Refresh Token for that access level. ...用户并未完全注销,但在下次登录时,他会获得两个新的 JWT,一个用于常规用户访问的访问令牌和一个用于该访问级别的匹配刷新令牌。

What do you exactly mean with on the next login ?下次登录时的确切含义是什么? My confusion here is that if the objective is not to logout the user, then there won't be a next login.我的困惑是,如果目标不是注销用户,则不会有下一次登录。 I guess this could mean that almost to the end of the refresh token expiration you would want to do your downgrade request and use the still valid refresh token to get a new pair of tokens with less permissions.我想这可能意味着几乎在刷新令牌到期时,您会想要执行降级请求并使用仍然有效的刷新令牌来获得一对具有较少权限的新令牌。

According to the OAuth specification you can perform a refresh token request and ask the server for an access token that has less scopes than the one you currently have.根据 OAuth 规范,您可以执行刷新令牌请求并要求服务器提供一个范围比您当前拥有的范围小的访问令牌。 However, it also dictates that if a new refresh token is returned, then that token needs to have the exact same scope as the refresh token included in the request.但是,它还规定如果返回新的刷新令牌,则该令牌需要与请求中包含的刷新令牌具有完全相同的范围。

Personally, for this scenario I would consider instead of downgrading tokens just ensure that in order to perform any administrator related operation the user must be an administrator and actually provided his credentials in the last 24 hours.就我个人而言,对于这种情况,我会考虑而不是降级令牌,只需确保为了执行任何管理员相关操作,用户必须是管理员并且在过去 24 小时内实际提供了他的凭据 You could accomplish this by tracking the date and time a given user actually performed a login (by providing their credentials) and then authorize administrator actions based on that value.您可以通过跟踪给定用户实际执行登录的日期和时间(通过提供他们的凭据)然后根据该值授权管理员操作来实现此目的。 This way you can increase the lifetime of refresh tokens for the confidential client and only force the administrators to login again if they want to perform a privileged tasks and their current tokens aren't fresh enough.通过这种方式,您可以增加机密客户端的刷新令牌的生命周期,并且只有在管理员想要执行特权任务并且他们当前的令牌不够新鲜时才强制他们再次登录。

Finally, still on the subject of refresh tokens (with focus on the security considerations section)... when you say web app for the public client I'm assuming it's a browser-based Javascript application.最后,仍然是关于刷新令牌的主题(重点是安全考虑部分)......当你说公共客户端的网络应用程序时,我假设它是一个基于浏览器的 Javascript 应用程序。 If this is correct it's generally not recommended to use refresh tokens for these applications because refresh tokens are usually long-lived (in your case they seem to never expire) and the browser cannot ensure secure storage for them.如果这是正确的,通常不建议为这些应用程序使用刷新令牌,因为刷新令牌通常是长期存在的(在您的情况下它们似乎永远不会过期)并且浏览器无法确保它们的安全存储。 This increases the likelihood of them leaking which would give an attacker access to the application for the lifetime of the token.这增加了它们泄漏的可能性,这将使攻击者在令牌的生命周期内访问应用程序。 You may have other constraints that make this security consideration not applicable, but I wanted to call your attention to it nonetheless.您可能还有其他限制使此安全考虑不适用,但我还是想提请您注意。

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

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