gpt4 book ai didi

c# - ASP.NET Core Identity - 使 token (电子邮件确认、密码重置等)在不同服务器上有效?

转载 作者:行者123 更新时间:2023-12-02 03:50:46 26 4
gpt4 key购买 nike

我正在使用 ASP.NET Core Identity 和 IdentityServer4 创建身份验证服务。一般情况下一切正常,但我遇到了一个问题,因为在我们的实时环境中它托管在多个服务器上,在这种情况下,在一台服务器上生成的 token (例如密码重置 token )无效在另一个。

我正在像这样设置身份(自定义用户存储等在其他地方注册):

 services.AddDataProtection()
.SetApplicationName("IdentityService");

services.AddIdentity<ApplicationUser, ApplicationRole>(options =>
{
options.Password.RequireNonAlphanumeric = false;
})
.AddDefaultTokenProviders();

如您所见,我尝试设置应用程序名称,使其在每台服务器上都相同,但这并没有解决问题。

我发现I can create an IXmlRepository它将用于存储 Identity 使用的 key :

services.AddDataProtection()
.SetApplicationName("IdentityService");
.AddKeyManagementOptions(s => s.XmlRepository = new CustomXmlRepo());

如果我实现这个并将 key 存储在我们的数据库中,这会解决我的问题吗?还有其他(更好)的方法吗?

最佳答案

本文介绍了使 identityserver4 实现做好生产准备所需要做的事情 - 其中一项要求是数据保护 key 的共享和持久存储:

IdentityServer4 指南:http://docs.identityserver.io/en/latest/topics/deployment.html

配置 ASP.NET Core 数据保护:https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-3.1

实现您自己的方法绝对没问题 - 只要确保它们存储的位置受到充分保护即可。

关于c# - ASP.NET Core Identity - 使 token (电子邮件确认、密码重置等)在不同服务器上有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59394909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com