ITicketStore AuthenticationTicket ExpiresUtc 值始终为 14 天

ITicketStore AuthenticationTicket ExpiresUtc value always 14 days

我正在创建一个继承自 ITicketStore 的自定义票务商店,以便将用户令牌存储在数据库中,因为 cookie 由于保存令牌而变得太大。

我已经设置好一切并正常工作,但是,我无法将 ExpiresUtc 的值设为传递给 [=15= 的 AuthenticationTicket 中除 14 天以外的任何值] 方法。

查看我的 ADFS 实例,我的刷新令牌生命周期缩短至 5 分钟,访问令牌生命周期缩短至 2 分钟。我仍然无法将正确的值填入 AuthenticationTicket.

我发现我可以在 ITicketStore StoreAsync 方法中手动更改它,但这并不理想,因为如果要在 ADFS 上更改刷新令牌生命周期,则不会在此受到尊重。

ASP.net core 是否为此设置了自己的值? ADFS 是否自行设置值并覆盖我的值?可能发生了什么?

STARTUP.CS

    // Authentication / Authorization
    services.AddAuthentication(options =>
    {
        options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
        options.DefaultAuthenticateScheme = OpenIdConnectDefaults.AuthenticationScheme;
    })
    .AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
    {
        options.Authority = Configuration["OpenIdConnect:Authority"];
        options.Resource = Configuration["OpenIdConnect:Resource"];
        options.ClientId = Configuration["OpenIdConnect:ClientId"];
        options.ClientSecret = Configuration["OpenIdConnect:ClientSecret"];

        options.Scope.Clear();
        options.Scope.Add(Configuration["OpenIdConnect:Scopes"]);
        options.SaveTokens = true;
                
        options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
        options.GetClaimsFromUserInfoEndpoint = false;
    })
    .AddCookie(options =>
    {
        options.SessionStore = new CustomTicketStore(services);
    });

CustomTicketStore.CS

public async Task<string> StoreAsync(AuthenticationTicket ticket)

CustomTicketStore 基于以下实现:

https://ml-software.ch/posts/implementing-a-custom-iticketstore-for-asp-net-core-identity-update

ExpiresUtc 值由 CookieAuthenticationOptions.ExpireTimeSpan 控制,默认为 14 天。

OpenIdConnectOptions.UseTokenLifetime 可以覆盖它以使过期与身份验证令牌匹配。