ASP Identity CoreGeneratePasswordResetTokenAsync 已过期

2024-05-19

我已经在 .NET Core 2.1 中设置了一个 Identity Server 4 项目,一切正常,但是当我使用用户管理器生成重置密码令牌时,令牌在 24 小时后过期,我可以将其更改为 48 小时吗?

我发送重置令牌的代码如下所示:

var code = await _userManager.GeneratePasswordResetTokenAsync(user);

var callbackUrl = url.EmailConfirmationLink(user.Id, code, scheme);

我的配置服务如下所示:

   services.AddIdentity<ApplicationUser, IdentityRole>(config =>
        {
            config.SignIn.RequireConfirmedEmail = true;
        })
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

谢谢 :)


将以下代码添加到 Startup.cs 类中的 ConfigureServices() 方法应该会对您有所帮助。

services.Configure<DataProtectionTokenProviderOptions>(options =>
    options.TokenLifespan = TimeSpan.FromDays(2));

默认令牌寿命为 24 小时(1 天)。请参考github https://github.com/aspnet/AspNetCore/blob/master/src/Identity/Core/src/DataProtectionTokenProviderOptions.cs and 代币期权 https://github.com/aspnet/AspNetCore/blob/master/src/Identity/Extensions.Core/src/TokenOptions.cs

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ASP Identity CoreGeneratePasswordResetTokenAsync 已过期 的相关文章

随机推荐