【问题标题】:NTLM authentication on specific route in ASP.NET CoreASP.NET Core 中特定路由的 NTLM 身份验证
【发布时间】:2017-07-23 16:43:01
【问题描述】:

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

.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 auth”按钮。 他可以输入凭据或按下按钮并使用他的操作系统身份进入。

【问题讨论】:

    标签: authentication asp.net-core forms-authentication windows-authentication


    【解决方案1】:

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

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

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

    • 在“ntlm”路径上删除此 UseCookieAuthentication
    • 创建一个控制器和一个带有“[Authorize]”属性的动作来触发身份验证
    • 显示HttpContext.User.Identity.Name;
    • 希望您能在此处正确验证 Windows 用户

    【讨论】:

    • 酷。对于您想通过 cookie 保护的操作,您可以指定 [Authorize(ActiveAuthenticationSchemes = "Cookies")] 以确保这是用于设置您的用户身份的中间件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 2018-02-24
    • 2016-07-05
    • 1970-01-01
    相关资源
    最近更新 更多