[英]SignalR with Client Certificate Authentication
我在IIS上托管了服务,该服务使用SignalR与客户端建立持久连接。
我正在尝试实现客户端证书身份验证,以便服务器可以根据它们发送的证书来验证客户端是有效客户端。 我正在使用Signalr的PersistentConnection。
客户端:我创建一个Connection对象,并创建一个X.509证书,该证书通过以下方式添加到连接中:
var connection = new Connection("localhost:8060/TheService/connect");
connection.AddClientCertificate(certificate);
connection.Start().Wait();
当客户端尝试连接时,我想验证其提供的证书是有效的证书。 因此,在服务器端,我重写了SignalR的PersistentConnection中的AuthorizeRequest()方法:
public class MyConnection : PersistentConnection
{
protected override Task OnReceived(IRequest request, string connectionId, string data)
{
return Connection.Broadcast("Server Received: " + data);
}
protected override bool AuthorizeRequest(IRequest request)
{
INameValueCollection headers = request.Headers;
foreach (KeyValuePair<string, string> entry in headers)
{
Console.WriteLine("Key: {0}, Value: {1}", entry.Key, entry.Value);
Console.WriteLine("");
}
return true;
}
}
我的问题是:如何在AuthorizeRequest方法中检索客户端证书? 我需要SignalR以某种方式获得对证书的访问权限,以便我可以对其进行验证,然后返回false(错误证书)或返回true(有效证书)。
谢谢!
您应该能够从作为参数获取的请求中获取证书。 HttpClientCertificate cert = request.GetHttpContext().Request.ClientCertificate;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.