我想使用基于证书的身份验证对连接到在 Kestrel 上运行的 ASP.NET Core Web API (.NET 5) 的客户端进行身份验证。
在我的中,Startup.cs我有以下内容ConfigureServices:
services.AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme)
.AddCertificate(options =>
{
options.AllowedCertificateTypes = CertificateTypes.All;
options.Events = new CertificateAuthenticationEvents
{
OnCertificateValidated = context =>
{
// More code to verify certificates
},
OnAuthenticationFailed = context =>
{
// More code
}
};
});
// Other services
Run Code Online (Sandbox Code Playgroud)
并在Configure:
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication();
app.UseEndpoints(endpoints =>
{
// Endpoints
});
Run Code Online (Sandbox Code Playgroud)
我在其中Program.cs包括:
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication();
app.UseEndpoints(endpoints =>
{
// Endpoints
});
Run Code Online (Sandbox Code Playgroud)
如果我在浏览器中连接到 API,它会提示我输入证书,但在我选择证书后,OnCertificateValidated …