Loading

IdentityServer Topics(6)- Windows身份验证

在Windows平台上,你可以让IdentityServer使用 Windows身份验证 对用户进行身份验证。 当你使用以下类型托管运行 IdentityServer 时, Windows身份验证功能可用:

  • 使用Kestrel服务器但需要使用IIS integration或者IIS
  • 使用HTTP.sys服务器

在这两种情况下,Windows身份认证将会触发 HttpContext 的 ChallengeAsync 方法,使用 Scheme "Windows"。快速入门:quickstart UI 的 AccountController 实现了该逻辑,

使用Kestrel

当使用Kestrel,在代码中使用IIS integration,且必须通过IIS来运行:

var host = new WebHostBuilder()
    .UseKestrel()
    .UseUrls("http://localhost:5000")
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseIISIntegration()
    .UseStartup<Startup>()
    .Build();

在使用WebHost.CreateDefaultBuilder方法设置WebHostBuilder时,Kestrel会自动配置。

此外,IIS(或IIS Express)中的虚拟目录必须启用Windows和匿名身份验证。

IIS integration 层将配置一个Windows身份验证处理程序到DI,可以通过身份验证服务调用。 通常在IdentityServer中,建议禁用此自动行为。 可以在 ConfigureServices 中完成:

services.Configure(iis =>
{
iis.AuthenticationDisplayName = "Windows";
iis.AutomaticAuthentication = false;
});

posted @ 2017-12-29 16:47  晓晨Master  阅读(3387)  评论(2编辑  收藏  举报