首页 > 解决方案 > 如何在 openiddict 中设置 expires_in

问题描述

我想在 asp.net core 2.2 服务器上使用 openiddict 2.0.1 使用 oauth,有效期为一天,此时我可以使用刷新令牌(尽管我也会在之前检查未经授权的访问问题到期)。但是,我无法弄清楚如何设置到期时间。我总是将 expires_in 返回为 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));

然后在我的授权上下文(令牌处理程序)中:

// 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);

返回值已将 expires_in 设置为 3600 - 即:1 小时。但这似乎不是我设定的。expires_at 没有任何声明,这似乎是源代码用来生成 3600 的内容(甚至不确定如何设置它?)。

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

谢谢,斯特凡

标签: securityasp.net-coreasp.net-identityopeniddict

解决方案


推荐阅读