c# - 带有 Windows/AD 身份验证的 IdentityServer4 不起作用?

标签 c# asp.net-core identityserver4

我为 IdentityServer4 创建了一个新项目并包含了 QuickUI。然后我点击链接 http://docs.identityserver.io/en/latest/topics/windows.html添加 Windows 身份验证。

startup.cs

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();
    }
}

Program.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 .我发现 DisplayNameawait _schemeProvider.GetAllSchemesAsync()为空且 schema.Nameidsrv.external而不是 Windows (AccountOptions.WindowsAuthenticationSchemeName)。

AccountController.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 身份验证”。

关于c# - 带有 Windows/AD 身份验证的 IdentityServer4 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55521359/

相关文章:

c# - 身份服务器 4 和 Azure AD

c# - 在.Net Core中将文件从url下载到本地设备

c# - IdentityModel2 TokenClient 资源所有者密码

c# - 创建泛型类型实例的方法

c# - 在 C# 中使用(复杂的)C 结构

c# - ASP.NET Core 1.1 在本地运行良好,但发布到 Azure 时显示 "An error occurred while starting the application."

asp.net-core - .net core 在运行时加载 *.deps.json 以加载依赖程序集的正确版本

c# - 身份服务器 4 - 配置了允许的来源但不允许来源

c# - WriteableBitmap 在 Silverlight 4 中有新功能吗?

c# - 如何使用 c# 卸载软件,方法是调用该软件的注册表文件中列出的 Software UninstallString 但进程不工作