ssl - 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();
}
}
}
解决方案
正如 Ruard van Elburg 所说,看起来我的 Identity Server 4 版本不是最新的。当我更新到最新的(2.5.0)时,它起作用了。
推荐阅读
- python - 使用 Python 将字符串中的正斜杠替换为反斜杠
- android - 将按钮大小调整到一定比例
- laravel - 如何更改 Tymon JWT 包 laravel 中的响应消息
- mysql - MySQL utf-8 无法识别特殊字符
- azure - Azure B2C 用户流 v2.0(注册和登录) - 无法找到 Userinfo 端点
- json - 在 React Native 中重新映射 Firebase JSON 数据
- authentication - Azure ADB2C 多 Web API 身份验证
- swift - SwiftUI:停止永远重复的动画
- spring-webflux - 如何在 spring-webflux 中使用请求和会话范围(截至最新版本)
- java - 如何在 Android Studio 中压缩 Kotlin 项目