使用 WindowsCredentials 连接到 TfsTeamProjectCollection

Connect to TfsTeamProjectCollection using WindowsCredentials

我想使用与登录 windows 相同的凭据连接到 TfsProjectCollection。这甚至可能吗?

我现在正在使用具有以下代码的替代凭据进行连接:

NetworkCredential credential = new NetworkCredential(this._username, this._password);
VssBasicCredential basicCred = new VssBasicCredential(credential);
try
{
    _tfsDataConnection = new TfsTeamProjectCollection(new Uri(this._tfsLink), basicCred);

    // VssData Part

    Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
    var url = new Uri(_tfsLink);

    VssCredentials vsc = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(
        new NetworkCredential(this._username, this._password)));
    VssConnection connection = new VssConnection(url, vsc);

    _vssDataConnection = connection.GetClient<BuildHttpClient>();
}

我需要从该服务器获取构建和项目。

这是我尝试过的方法,但出现错误,好像我没有被授权。

_tfsDataConnection = new TfsTeamProjectCollection(new Uri(this._tfsLink));
try
{
    VssCredentials vsc = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(CredentialCache.DefaultNetworkCredentials));
    VssConnection connection = new VssConnection(new Uri(_tfsLink), vsc);
    _vssDataConnection = connection.GetClient<BuildHttpClient>();
}

不要传递任何显式凭据:经典客户端SDK 将使用当前用户。 _tfsDataConnection = new TfsTeamProjectCollection(new Uri(this._tfsLink)); _tfsDataConnection.Authenticate();

REST SDK类似,应该使用默认构造函数。 VssConnection connection = new VssConnection(new Uri(_tfsLink), new VssCredentials()); _vssDataConnection = connection.GetClient<BuildHttpClient>();