我正在尝试使用OWIN管道实现客户端证书认证,根据Dominick Baier 2013年末的博客(http://leastprivilege.com/2013/11/11/client-certificate-authentication-middleware-for-katana/),您可以通过创建自定义身份验证处理程序来实现。
public class ClientCertificateAuthenticationHandler : AuthenticationHandler<ClientCertificateAuthenticationOptions>
{
protected override Task<AuthenticationTicket> AuthenticateCoreAsync()
{
var cert = Context.Get<X509Certificate2>("ssl.ClientCertificate");
if (cert == null)
{
return Task.FromResult<AuthenticationTicket>(null);
}
try
{
Options.Validator.Validate(cert);
}
catch
{
return Task.FromResult<AuthenticationTicket>(null);
}
var claims = GetClaimsFromCertificate(cert, cert.Issuer, Options.CreateExtendedClaimSet);
var identity = new ClaimsIdentity(Options.AuthenticationType);
identity.AddClaims(claims);
var ticket = new AuthenticationTicket(identity, new AuthenticationProperties());
return Task.FromResult(ticket);
}
}
问题在于
GetClaimsFromCertificate
方法不再出现在基类中,也不在 ClaimsIdentity
类中。我猜测它已经移动了位置,但是我已经在所有明显的地方搜索过了,却一无所获。请问有人知道这个有用的方法去哪里了吗?
GetClaimsFromCertificate
包含在Microsoft.IdentityModel.Claims
命名空间中,您可以从NuGet获取Microsoft.IdentityModel包来获得它。我还没有尝试过,但我希望这可以帮助到你 :) - xnr_z