我试图访问https://visualstudio.com (原名https://tfs.visualstudio.com , http://www.tfspreview.com )从我写的.NET Windows服务。
我想用新的基本身份验证,但我无法找到一个方法来做到这一点。
我发现很多链接到博客文章的Team Foundation服务更新- 8月27日 ,但它使用的是团队资源管理器无处不在的Java客户端TFS。
有TFS的.NET对象模型的新版本,以支持基本的认证?
顺便说一句,我先后登录时使用的服务帐户。 这个答案是非常有用的。
首先,你需要有至少的Visual Studio 2012 Update 1的计算机上安装。 它包括一个更新Microsoft.TeamFoundation.Client.dll
与组件BasicAuthCredential
类。
下面的代码做到这一点,从巴克的博客文章如何连接到Team Foundation服务 。
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);
}
}
}
已经有一些更新的认证。 对于.NET应用程序,我们现在建议使用VSTS客户端库 。 另一种选择是使用Azure的活动目录库(ADAL)。 欲了解更多信息和样品检出VSTS的认证文件 。
文章来源: How to authenticate to Visual Studio Team Services with the new basic authentication from a .Net Windows Service?