首页 > 解决方案 > Identity Server 中缺少相互 TLS 引用

问题描述

下午好,

我一直在关注将双向 TLS 添加到身份服务器的文档。

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

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

我收到此导入参考错误:

“身份服务器选项”不包含“MutualTls”的定义...

对于AddMutualTlsSecretValidators.

这些引用是否在单独的库中?我搜索了文档并且已经挖掘了一段时间,但似乎找不到任何东西。

您可以提供的任何帮助将不胜感激。

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

这是我的启动课程:

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

标签: ssljwtcertificateidentityserver4tls1.2

解决方案


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


推荐阅读