gpt4 book ai didi

access-token - IdentityServer4 访问 token 生命周期

转载 作者:行者123 更新时间:2023-12-03 14:33:45 41 4
gpt4 key购买 nike

我使用的是 IdentityServer4,它的配置在数据库中。客户端(oidc)上有一个静默更新。我为客户端设置了以下生命周期设置:

AbsoluteRefreshTokenLifetime =  60 * 30,//30 mins
AccessTokenLifetime = 60 * 5,//5 mins
SlidingRefreshTokenLifetime = 60 * 15 // 15 mins
应该发生什么? token 的生命周期应该是多久?什么时候应该要求用户再次登录?没有关于 token 生命周期何时刷新以及何时过期的明确文档。

最佳答案

Access tokens can come in two flavours - self-contained or reference.

A JWT token would be a self-contained access token - it’s a protected data structure with claims and an expiration. Once an API has learned about the key material, it can validate self-contained tokens without needing to communicate with the issuer. This makes JWTs hard to revoke. They will stay valid until they expire.



来自 http://docs.identityserver.io/en/latest/topics/reference_tokens.html#reference-tokens

Refresh tokens allow gaining long lived access to APIs.

You typically want to keep the lifetime of access tokens as short as possible, but at the same time don’t want to bother the user over and over again with doing a front-channel roundtrips to IdentityServer for requesting new ones.

Refresh tokens allow requesting new access tokens without user interaction. Every time the client refreshes a token it needs to make an (authenticated) back-channel call to IdentityServer. This allows checking if the refresh token is still valid, or has been revoked in the meantime.



来自 http://docs.identityserver.io/en/latest/topics/grant_types.html#refresh-tokens

所以访问 token 是自包含的,这意味着它不能被修改。 token 一旦发出,就一直有效,直到过期。这就是为什么您要使用短期 token 的原因。

为了自动化访问 token 更新过程,您可以使用刷新 token 。这是一个强大的 token ,因为它可以用于在没有用户交互的情况下请求访问 token 。刷新 token 应该是长期存在的(至少比访问 token 长)。

一旦刷新 token 过期,用户必须再次登录。如果没有滑动过期,刷新 token 将在绝对时间内过期,让用户再次登录。

通过滑动过期,您可以设置更短的刷新 token 生命周期。因为每次请求访问 token 时,都会发出一个新的刷新 token 。延长生命周期并使使用的刷新 token 无效。

只要刷新 token 有效,用户就可以访问资源而无需再次登录。在您的情况下,如果用户处于非事件状态超过 30 分钟,它就会过期。

访问 token 不会自动刷新。您需要在客户端中添加代码以请求新的访问 token 。如果刷新 token 不可用或已过期,您可以将用户发送到登录页面。

关于access-token - IdentityServer4 访问 token 生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50363450/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com