ASP.NET Core中特定路由上的NTLM身份验证

问题描述 投票:1回答:1

尝试在测试环境中实现主题。

.UseWebListener(options=>
{
    options.ListenerSettings.Authentication.Schemes = AuthenticationSchemes.NTLM |
                                                      AuthenticationSchemes.Negotiate;
    options.ListenerSettings.Authentication.AllowAnonymous = true;
})

app.UseWhen(context => context.Request.Path.StartsWithSegments("/ntlm"),
            builder => builder.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AutomaticAuthenticate = true,
                AutomaticChallenge = true,
                LoginPath = "/Main/Login",
                LogoutPath = "/Main/Logout",
                AuthenticationScheme = "NTLM", AccessDeniedPath = "/Main/Deny"
            }
            ));

app.UseWhen(context => !context.Request.Path.StartsWithSegments("/ntlm"),
            builder => builder.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AutomaticAuthenticate = false,
                AutomaticChallenge = false,
                LoginPath = "/Main/Login",
                LogoutPath = "/Main/Logout",
                AuthenticationScheme = "Cookies"
            }
            ));

但似乎没有区别,请求路径是否以“/ ntlm”开头。

我尝试运行两个WebListener,但我认为还有更多的开销。

我想要实现的目标:用户使用登录表单进入起始页面,并在其上显示“Windows身份验证”按钮。他可以输入凭据或按下按钮,然后输入他的操作系统标识。

authentication asp.net-core forms-authentication windows-authentication
1个回答
2
投票

我正在使用IIS做一些非常相似的事情,而不是WebListener,但也许我可以告诉你一些可以提供帮助的事情。

您已经为我的IIS配置了WebListener以允许匿名访问,但也能够协商验证,该部分应该没问题。

但是在“/ ntlm”url路径上,您已经安装了一个CookieAuthentication中间件,该中间件将尝试在传入请求中查找cookie以对用户进行身份验证,我认为这不是您想要的。相反,在“/ ntlm”路径上,您希望重用来自WebListener检测到的NTLM或Kerberos数据包的标识。在我的情况下,正确设置时,它是一个负责设置身份的IIS中间件。我会建议:

  • 在“ntlm”路径上删除此UseCookieAuthentication
  • 使用“[Authorize]”属性创建控制器和操作以触发身份验证
  • 显示HttpContext.User.Identity.Name;
  • 希望你能在这里对Windows用户进行适当的身份验证
© www.soinside.com 2019 - 2024. All rights reserved.