【发布时间】:2015-10-29 19:36:49
【问题描述】:
我正在尝试使用 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 类中。我猜它已经移动了,但我已经搜索了所有明显的地方并画了一个空白。有谁知道这个有用的方法发生了什么?
【问题讨论】:
-
我有点晚了,但我遇到了同样的问题,根据MSDN
GetClaimsFromCertificate包含在Microsoft.IdentityModel.Claims命名空间中,您可以从NuGet 的Microsoft.IdentityModel 包中获取它。我还没有尝试过,但我希望这可以帮助你:)
标签: c# owin client-certificates