簡體   English   中英

帶有 Windows/AD 身份驗證的 IdentityServer4 不起作用?

[英]IdentityServer4 with Windows/AD authentication not working?

我為 IdentityServer4 創建了一個新項目並包含了 QuickUI。 然后我按照鏈接http://docs.identityserver.io/en/latest/topics/windows.html添加 Windows 身份驗證。

啟動文件

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddTestUsers(Config.GetUsers())
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryClients(Config.GetClients());

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

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); }

        app.UseIdentityServer();
        app.UseStaticFiles();
        app.UseMvcWithDefaultRoute();
    }
}

程序.cs

public class Program
{
    public static void Main(string[] args) => CreateWebHostBuilder(args).Build().Run();

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>();
}

但是,頁面https://localhost:44378/Account/Login 中仍然沒有顯示外部登錄按鈕。 我發現await _schemeProvider.GetAllSchemesAsync()DisplayName為 null 並且schema.Nameidsrv.external而不是Windows ( AccountOptions.WindowsAuthenticationSchemeName )。

賬戶控制器.cs

private async Task<LoginViewModel> BuildLoginViewModelAsync(string returnUrl)

var schemes = await _schemeProvider.GetAllSchemesAsync();

var providers = schemes
    .Where(x => x.DisplayName != null || // schemes.DisplayName is null
                (x.Name.Equals(AccountOptions.WindowsAuthenticationSchemeName, // "idsrv.external" != "Windows"
                  StringComparison.OrdinalIgnoreCase))
    )
    .Select(x => new ExternalProvider
    {
        DisplayName = x.DisplayName,
        AuthenticationScheme = x.Name
    }).ToList();

如何解決問題?

順便說一句,我只需要針對 Windows/AD 進行身份驗證,所以我不需要外部按鈕。 如何更改代碼?

它需要禁用“匿名身份驗證”並啟用“Windows 身份驗證”。

使用 Kestrel 時,必須使用 IIS 集成:

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

ConfigureServices 中的更改。

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

您必須啟用 Windows 和匿名身份驗證(IIS 或 IISExpress)

注意:如果您使用的是 VisualStudio 和 IISExpress,請以“管理員”身份運行 Visual Studio。

有關詳細信息:請參閱此鏈接: https : //docs.identityserver.io/en/3.1.0/topics/windows.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM