无法理解 IdentityTokenLifetime 以及我的 JWT 持续多长时间

我无法理解 JWT 令牌的生命周期。

  • IdentityTokenLifetime(以秒为单位的身份令牌的生命周期(默认为 300 秒/5 分钟)

= 120 / 60 = 2 分钟

IdentityTokenLifetime 的目的是什么?

  • accessTokenLifetime(访问令牌的生命周期以秒为单位(默认为 3600 秒/1 小时)

= 120 / 60 = 2 分钟

  • SlidingRefreshTokenLifetime(刷新令牌的滑动生命周期,以秒为单位。默认为 1296000 秒/15 天)

= 300 / 60 = 5 分钟

从奇怪的摘要评论信息来看,我真的不明白 JWT 令牌在几分钟内存活了多久。

public static IEnumerable<Client> getclients(IConfiguration configuration) =>
    new List<Client>
    {
        new()
        {
            ClientName = configuration["AuthConfiguration:ClientName"],ClientId = configuration["AuthConfiguration:ClientId"],ClientSecrets = { new Secret(configuration["AuthConfiguration:ClientSecret"].Sha256()) },AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordandClientCredentials,accessTokenType = accessTokenType.Jwt,AllowOfflineaccess = true,accessTokenLifetime = 120,IdentityTokenLifetime = 120,UpdateaccessTokenClaimsOnRefresh = true,SlidingRefreshTokenLifetime = 300,RefreshTokenExpiration = TokenExpiration.Absolute,RefreshTokenUsage = TokenUsage.OneTimeonly,AlwaysSendClientClaims = true,AllowedScopes =
            {
                IdentityServerConstants.StandardScopes.OpenId,IdentityServerConstants.StandardScopes.Profile,IdentityServerConstants.StandardScopes.Offlineaccess,configuration["AuthConfiguration:ApiName"]
            }
        }
    };
wendy446 回答:无法理解 IdentityTokenLifetime 以及我的 JWT 持续多长时间

根据您的示例,身份验证成功后,将创建以下令牌:

  1. 300 秒后过期的刷新令牌。 TokenExpiration.Absolute 值表示不会刷新刷新令牌。这通常是太短的值。刷新令牌通常持续数天。刷新令牌过期后,将无法再刷新令牌,用户将需要再次进行身份验证。
  2. 在 120 秒后过期的访问令牌。如果 Refresh Token 未过期,则会创建一个新的 Access Token。
  3. 在 120 秒后过期的身份令牌。如果 Refresh Token 未过期,则会创建一个新的 Identity Token。

要获得以分钟为单位的每个令牌的生命周期,将秒除以 60。

本文链接:https://www.f2er.com/167.html

大家都在问