在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.AuthenticationDisplayName = "Windows";
iis.AutomaticAuthentication = false;
});