【发布时间】:2021-12-18 19:41:11
【问题描述】:
在 ID4 上提问非常困难。此外,我可以通过谷歌搜索的所有相关讨论都指向不存在的代码示例链接。
我所拥有的:一个 Angular 客户端使用由 Microsoft 提供的 MVC 页面组成的 ID4 身份验证,托管在 ASP.NET Core 中。
Startup.cs
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<AppDbContext>();
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, AppDbContext>();
services.AddAuthentication()
.AddIdentityServerJwt();
. . .
app.UseAuthentication();
app.UseIdentityServer();
app.UseAuthorization();
authorize.service.ts
const settings: any = await response.json();
settings.automaticSilentRenew = true;
settings.includeIdTokenInSilentRenew = true;
this.userManager = new UserManager(settings);
用例:用户登录网页,勾选记住我复选框并使用经过身份验证的网站部分。如果服务器重新启动 - 令牌丢失并且用户与网站的交互被破坏 - 例如webbrowser 控制台中没有错误,如果用户尝试访问任何服务器端数据,也不会发生任何事情。好像什么都没有。好像不是身份验证有问题。
只能通过手动注销/登录来修复。或者通过打开新标签并再次转到应用程序。
是否有关于如何 a) 检测客户端令牌已损坏和 b) 请求新令牌的简单说明?
编辑如果用户在下一个工作日继续使用网站或打开新的浏览器选项卡(无需重新启动服务器),ID4 将按预期工作 - 无需登录。
提琴手:
【问题讨论】:
-
什么是服务器? tokens are lost 是什么意思? (我相信您通常会将它们放入本地存储中。)您是否使用刷新令牌?即使您从 Angular 开始另一个登录流程,IdentityServer 也应该直接重定向回来,因为它的 cookie 从用户上次登录时仍然在浏览器中——除非它们已经过期。
标签: c# angular asp.net-core identityserver4