使用客户端证书身份验证通过 TFS API 连接到 TFS

Connecting to TFS through TFS API using client certificate authentication

我想从未加入域的计算机(Azure 角色)连接到我的 TFS,因此该计算机必须以某种方式向我的 TFS 进行身份验证。我知道如何使用用户名+密码来完成,但我不想将其保存在机器上。

所以,我想Configure my TFS for client certificate authentication,为域用户颁发客户端证书,将其安装在Azure角色上,并使用它进行连接。

上面的文章说要使用 tfpt tweakuimay actually be tfpt connections),但是没有任何 UI。

但无论哪种方式,我都想使用 TFS API 进行连接。但是,我不知道如何:

// ------- I know username+password... -------------------
var NetCreds = new System.Net.NetworkCredential("username", "password");  // No certificate here
var collection2 = new TfsTeamProjectCollection(new Uri("myuri"), new TfsClientCredentials(new WindowsCredential(NetCreds)));

// ------- And I know how to get a certificate... --------
var certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
certStore.Open(OpenFlags.ReadOnly);
var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, "Thumbprint-that-I'll-provide", validOnly: true);
X509Certificate2 cert = certCollection.OfType<X509Certificate2>().Single();

// -------- But how to connect with it? ------------------
var TfsCreds = new TfsClientCredentials(cert); // Nope, no such method...
var collection = new TfsTeamProjectCollection("myuri", TfsCreds);

那么,如何使用客户端证书身份验证连接到 TFS?

该页面需要更新。末尾有一条重要评论,内容如下。您将需要使用这些较新的命令。

TFS 2010 发生的一件事是,服务器端较旧的 tfsadminutil configureconnections 命令已替换为 tfsconfig 证书 (http://msdn.microsoft.com/en-us/library/ee349260.aspx)。在客户端,tf 证书命令替换了 tfpt tweakui。