我正在尝试为 Identity Server 4 实施 Windows 身份验证。
在我的代码中,我使用了与Identity server 4 windows authentication using extension Grant not working中描述的解决方案类似的解决方案
首先,我使用HttpSys
具有适当方案的服务器
builder.WebHost.UseHttpSys(options =>
{
options.Authentication.Schemes = AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM;;
options.Authentication.AllowAnonymous = false;
});
然后我添加Negotiate
身份验证:
builder.Services.AddAuthentication(IdentityServerConstants.LocalApi.AuthenticationScheme)
.AddIdentityServerAuthentication(options =>
{
options.Authority = "http://localhost:5000";
options.ApiName = "server.api";
})
.AddNegotiate()
.AddLocalApi();
我还用这样的代码扩展了 Identity Server:
.AddExtensionGrantValidator<WinAuthGrantValidator>()
(代码WinAuthGrantValidator
可以在这个答案 Identity server 4 windows authentication using extension Grant not working中找到)
这似乎有效,并且用户已通过身份验证。WindowsIdentity
在HttpContext.User.Identity
- 到目前为止,非常好。
现在是我的问题,我也ProfileService
像这样在 Identity Server 4 中注册:
.AddProfileService<ProfileService>()
它将一些数据添加到登录用户(作为附加声明) - 如果用户使用用户名和密码登录,则此方法有效。
不幸的是,当我使用 Windows 身份验证进行日志记录时,它会ProfileService
被调用并添加一些声明,IssuedClaims
但后来(在应用程序代码中)我尝试从中读取这些声明,HttpContext.User
但没有它。你能帮我弄清楚为什么会这样吗?
非常感谢!