Owin和Windows Auth(mvc5) - 使用Windows身份验证作为登录的一部分

Kie*_*one 6 authentication windows-authentication owin asp.net-mvc-5

我正在尝试使用部分使用Windows Auth 的MVC5 webapp .

我的意思是,它实际上是基于表单/ cookie的身份验证,但请求用户的Windows主体构成了他们的登录凭据的一部分.

例如,登录页面会显示"您已被识别为somedomain\kierenj.请输入密码以登录." 如果他们输入了正确的代码,则会设置cookie并登录.

如果Windows身份验证失败,则仍会显示登录页面,但会被禁用.

我已经尝试过像这样的WindowsPrincipalHanlder:https://github.com/JabbR/JabbR/blob/master/JabbR/Middleware/WindowsPrincipalHandler.cs

它的要点是,如果我启用Windows身份验证并禁用匿名身份验证,那么Owin(或者可能是它的cookie auth部分)重定向到登录页面 - 它重定向到登录页面 - 它是一个重定向循环.

注意我使用的是非常简化的Owin设置. UseCookieAuthenticationApplicationCookie类型和LoginPath指定; 然后我SignIn从我的帐户控制器那样打电话:

        var claims = new[] {
            new Claim(ClaimTypes.Name, "Username"),
            new Claim(ClaimTypes.Role, "AuthenticatedUser")
        };
        AuthenticationManager.SignIn(new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie));
Run Code Online (Sandbox Code Playgroud)

(首先检查WindowsIdentity.GetCurrent()过)

我真的需要编写自己的Owin cookie auth中间件版本吗?我可以获取源代码以便我可以调试/派生吗?

zvo*_*kov -2

为了避免重定向循环,在服务登录页面的控制器的构造函数中,尝试将当前 HttpContext 的 Response.SuppressFormsAuthenticationRedirect 设置为true