我成功地遵循了IdentityServer4(https://deblokt.com/2020/01/24/01-identityserver4-quickstart-net-core-3-1/)上的Deblokt教程。本教程使用IdentityServer4 QuickstartUI。使用AspNet身份数据库的用户ID /密码身份验证正在运行。
我正在使用最新的.Net Core(3.1),它与本教程稍有不同,但是可以正常工作。
现在,我正在尝试添加Windows身份验证并遇到运行时错误。使我困惑的是,错误发生在Windows用户成功通过身份验证后。我正在使用Google Chrome在Visual Studio 2019内部的Windows 10计算机上以调试模式在本地运行。根据IdentityServer4文档(https://identityserver4.readthedocs.io/en/latest/topics/windows.html#using-kestrel),将其添加到Startup.cs:
services.Configure<IISServerOptions>(iis =>
{
iis.AuthenticationDisplayName = "Windows";
iis.AutomaticAuthentication = false;
});
然后我右键单击该项目,选择“属性”,选择“调试”选项卡,并选中“ Windows身份验证”:
当我导航到/ Account / Login时,这将显示“ Windows”按钮:
单击“ Windows”按钮后,将在ExternalController的“ Challenge”方法内处理回发,其中“ Windows”作为提供程序参数,而“〜/”作为returnUrl参数。由于提供者参数为“ Windows”,因此此方法将调用returnRerl参数传递给ProcessWindowsLoginAsync。
[第一次,ProcessWindowsLoginAsync调用HttpContext.AuthenticateAsync(“ Windows”),它返回一个空的Principal,这将导致该方法重新调用/ External / Challenge(“ Windows”),该方法第二次调用ProcessWindowsLoginAsync。依次调用HttpContext.AuthenticateAsync(“ Windows”),并且第二次调用成功-HttpContext.AuthenticateAsync返回Windows主体(是我),我可以在调试器中查看它,并确保所有信息正确。
ProcessWindowsLoginAsync然后进行此调用:
await HttpContext.SignInAsync(
IdentityServer4.IdentityServerConstants.ExternalCookieAuthenticationScheme,
new ClaimsPrincipal(id),
props
);
此执行没有错误。 “ id”参数是一个ClaimsIdentity,其中2个声明是从我的Windows身份,主题和名称中提取的。
此时看来一切都很好。方法ProcessWindowsLoginAsync以重定向到/ External / Callback结尾。这是发生错误的地方。 / External / Callback方法的顶部包含此代码段,并引发您看到的异常。由于某些原因,未知的HttpContext.AuthenticateAsync无法成功。
var result = await HttpContext.AuthenticateAsync(IdentityConstants.ExternalScheme);
if (result?.Succeeded != true)
{
throw new Exception("External authentication error");
}
“结果”对象的“成功”值是false,而“无”值是true,其他属性(Principal,Properties和Ticket)均为空。
任何建议都值得赞赏。
我成功地遵循了IdentityServer4上的Deblokt教程(https://deblokt.com/2020/01/24/01-identityserver4-quickstart-net-core-3-1/)。本教程使用IdentityServer4 QuickstartUI。 ...