如何使用.Net Windows服务的新基本身份验证对Visual Studio Team Services进行身份验证?

时间:2012-11-06 06:44:07

标签: c# .net tfs azure-devops basic-authentication

我正在尝试从我在.NET上编写的Windows服务访问https://visualstudio.com(以前称为https://tfs.visualstudio.comhttp://www.tfspreview.com)。

我想使用新的基本身份验证,但我找不到办法。

我找到了很多链接到博客帖子Team Foundation Service updates - Aug 27,但它正在使用Team Explorer Everywhere Java客户端进行TFS。

是否有新版本的TFS .NET对象模型支持基本身份验证?

顺便提一下,我已经连续登录了服务帐户。 This answer非常有用。

2 个答案:

答案 0 :(得分:12)

首先,您需要在计算机上安装至少Visual Studio 2012 Update 1。它包含一个更新的Microsoft.TeamFoundation.Client.dll程序集,其中包含BasicAuthCredential类。

以下是从Buck's blog post How to connect to Team Foundation Service开始执行此操作的代码。

using System;
using System.Net;
using Microsoft.TeamFoundation.Client;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            NetworkCredential netCred = new NetworkCredential(
                "yourbasicauthusername@live.com",
                "yourbasicauthpassword");
            BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
            TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
            tfsCred.AllowInteractive = false;

            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
                new Uri("https://YourAccountName.visualstudio.com/DefaultCollection"),
                tfsCred);

            tpc.Authenticate();

            Console.WriteLine(tpc.InstanceId);
        }
    }
}

答案 1 :(得分:0)

对身份验证进行了一些更新。对于.NET应用程序,我们现在建议使用VSTS client libraries。另一种选择是使用Azure Active Directory库(ADAL)。有关更多信息和示例,请查看VSTS's authentication documentation

相关问题