Identity Server 中缺少相互 TLS 引用

Missing Mutual TLS Reference in Identity Server

下午好,

我一直在关注 documentation 以向 Identity Server 添加双向 TLS。

但是,当我添加以下代码时:

    var builder = services.AddIdentityServer(options =>
    {
        options.MutualTls.Enabled = true;
        options.MutualTls.ClientCertificateAuthenticationScheme = "x509";
    });

我收到此导入引用错误:

'Identity Server Options' does not contain a definition for 'MutualTls'...

AddMutualTlsSecretValidators也一样。

这些参考文献是否在单独的库中?我搜索了文档并研究了一段时间,但似乎找不到任何东西。

我们将不胜感激。

我在我的 Startup class 中尝试了各种导入,例如 IdentityModel、idunno.Authentication.Certificate 和 IdentityServer4,但这些都没有帮助。

这是我的创业公司 class:

using IdentityModel;
using idunno.Authentication.Certificate;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;

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

            services.AddAuthentication()
                .AddCertificate("x509", options =>
                {
                    options.RevocationMode = System.Security.Cryptography.X509Certificates.X509RevocationMode.NoCheck;

                    options.Events = new CertificateAuthenticationEvents
                    {
                        OnValidateCertificate = context =>
                        {
                            context.Principal = Principal.CreateFromCertificate(context.ClientCertificate, includeAllClaims: true);
                            context.Success();

                            return Task.CompletedTask;
                        }
                    };
                });

            var builder = services.AddIdentityServer(options =>
            {
                // Complains about missing reference
                options.MutualTls.Enabled = true;
                // Complains about missing reference
                options.MutualTls.ClientCertificateAuthenticationScheme = "x509";

            })
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApis())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers())
            // Complains about missing reference
            .AddMutualTlsSecretValidators();
        }

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

            app.UseStaticFiles();

            app.UseIdentityServer();

            app.UseMvcWithDefaultRoute();
        }
    }
}

正如 Ruard van Elburg 所说,看来我的 Identity Server 4 版本不是最新的。当我更新到最新版本 (2.5.0) 时它起作用了。