我试图通过将主要组件分解为单独的Web服务器来使用微服务架构来实现Web应用程序。我正在使用ASP.NET Identity(仅限电子邮件/用户名登录,没有Facebook等)和“主”应用程序服务器来实现身份验证服务器。
我目前的挑战是弄清楚如果用户通过身份验证服务器登录,应用程序服务器将如何识别。由于身份验证服务器生成用户验证用户身份的令牌,我想它们存储在某个地方并且可以由应用程序服务器查询,但我不确定如何执行此操作。理想情况下,我的应用程序服务器WebAPI端点将能够使用[Authorize]注释。
问:一个服务器如何使用ASP.NET标识通过单独的身份验证服务器控制访问?
我通过执行以下操作(使用cookie身份验证)完成了类似的操作:
1 - 将cookie域设置为所有网站的TLD
我的 Startup.Auth.cs
看起来像这样:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => {
var identity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
//some additional claims and stuff specific to my needs
return Task.FromResult(identity);
})
},
CookieDomain = ".example.com"
});
2 - 更新所有网站的web.config以使用相同的 <machineKey />
我看起来像这样:
<machineKey
decryption="Auto"
decryptionKey="my_key"
validation="HMACSHA512"
validationKey="my_other_key" />
现在,我可以执行登录操作,比方说, account.example.com
,并将用户重定向到 site1.example.com
他们将被视为经过认证。
我通过执行以下操作(使用cookie身份验证)完成了类似的操作:
1 - 将cookie域设置为所有网站的TLD
我的 Startup.Auth.cs
看起来像这样:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => {
var identity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
//some additional claims and stuff specific to my needs
return Task.FromResult(identity);
})
},
CookieDomain = ".example.com"
});
2 - 更新所有网站的web.config以使用相同的 <machineKey />
我看起来像这样:
<machineKey
decryption="Auto"
decryptionKey="my_key"
validation="HMACSHA512"
validationKey="my_other_key" />
现在,我可以执行登录操作,比方说, account.example.com
,并将用户重定向到 site1.example.com
他们将被视为经过认证。