我有一个SignalR使用OWIN. 我想将 Windows 身份验证添加到传入的请求中。这可能吗?
我相信我可以通过这样的方式添加例如表单身份验证。
但是我找不到任何方法来使用 Windows 身份验证来做类似的事情。
我的后备计划是改为托管在 IIS 中,但如果可以的话,我更希望能够将我的应用程序保留为 Windows 服务。
我有一个SignalR使用OWIN. 我想将 Windows 身份验证添加到传入的请求中。这可能吗?
我相信我可以通过这样的方式添加例如表单身份验证。
但是我找不到任何方法来使用 Windows 身份验证来做类似的事情。
我的后备计划是改为托管在 IIS 中,但如果可以的话,我更希望能够将我的应用程序保留为 Windows 服务。
理想情况下会有一个 NTLM owin middlware,但由于没有中间件,您可以通过获取 HttpListener 的句柄并以这种方式启用身份验证来解决它(HttpListener 本身支持它):
public class Startup
{
public void Configuration(IAppBuilder app)
{
var listener = (HttpListener)app.Properties[typeof(HttpListener).FullName];
listener.AuthenticationSchemes = AuthenticationSchemes.Ntlm;
app.MapHubs();
}
}
我遇到了和你一样的问题,并决定实现一个 NTLM / Windows 身份验证中间件;
你可以在 Nuget 上找到它:
Install-Package Pysco68.Owin.Authentication.Ntlm
有关如何使用它的来源和更详细的信息可在此处获得:https ://github.com/pysco68/Pysco68.Owin.Authentication.Ntlm
最小用法示例可能如下所示:
public void Configuration(IAppBuilder app)
{
// use default sign in with application cookies
app.SetDefaultSignInAsAuthenticationType(
DefaultAuthenticationTypes.ApplicationCookie);
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie
});
// Enable NTLM authentication
app.UseNtlmAuthentication();
// .....
}
请注意,出于性能原因,我最终决定坚持使用 Cookie 身份验证,并将 NTLM 仅用于初始身份验证往返(因为请求数量很大)。