Security 如何在openiddict中设置expires_

Security 如何在openiddict中设置expires_,security,asp.net-core,asp.net-identity,openiddict,Security,Asp.net Core,Asp.net Identity,Openiddict,我想在asp.net core 2.2服务器上使用oauth,使用openiddict 2.0.1,到期时间为一天,此时我可以使用刷新令牌(尽管我还将在到期前检查未经授权的访问问题)。但是,我不知道如何设置到期时间。我总是以3600的形式返回 以下是我在服务器上的startup.cs中所做的操作: // Allow client applications to use the grant_type=password flow. options.AllowPasswordFlow(); // an

我想在asp.net core 2.2服务器上使用oauth,使用openiddict 2.0.1,到期时间为一天,此时我可以使用刷新令牌(尽管我还将在到期前检查未经授权的访问问题)。但是,我不知道如何设置到期时间。我总是以3600的形式返回

以下是我在服务器上的startup.cs中所做的操作:

// Allow client applications to use the grant_type=password flow.
options.AllowPasswordFlow();
// and refreshing
options.AllowRefreshTokenFlow();

options.SetAccessTokenLifetime(TimeSpan.FromDays(1));
options.SetRefreshTokenLifetime(TimeSpan.FromDays(14));
然后在我的授权上下文中(令牌处理程序):

返回值已设置为3600,即:1小时。但这似乎不是我设定的。没有关于expires_at的声明,这似乎是源代码生成3600的目的(甚至不知道如何设置它?)

如何确保令牌在1天而不是1小时内过期

谢谢,
Stefan

我无法重现您描述的行为:调用
options.SetAccessTokenLifetime(TimeSpan.FromDays(1))正确导致返回
“expires_in”:86400
属性(OpenIddict不使用
AuthenticationProperties
上的
ExpiresUtc
属性)。考虑在Github上发布一个RePro应用程序,我来看看。谢谢凯文。很高兴知道我没有错过任何明显的东西。我还有第二个站点要使用相同的基本代码构建,因此我将看看是否可以在那里重复它。您也可以直接在票据上设置生存时间:
ticket.SetAccessTokenLifetime(TimeSpan.FromDays(1))
// Create a new authentication ticket for the user's principal
var ticket = new AuthenticationTicket(
    principal,
    new AuthenticationProperties()
    {
        ExpiresUtc = DateTimeOffset.UtcNow.AddDays(1),
        IsPersistent = true
    },
    OpenIdConnectServerDefaults.AuthenticationScheme);

[...]
// Sign in the user
return SignIn(ticket.Principal, ticket.Properties, ticket.AuthenticationScheme);