TFS 2015 REST API Authentication

前端 未结 3 692
忘掉有多难
忘掉有多难 2020-12-04 01:13

We are trying to invoke the TFS 2015 REST API\'s from a web-page using Javascript and have a challenge in establishing valid authentication with the TFS server.

We

3条回答
  •  不知归路
    2020-12-04 01:57

    If possible, I would recommend using the .NET client libraries for Visual Studio Team Services (and TFS):

    https://www.visualstudio.com/en-us/docs/integrate/get-started/client-libraries/dotnet

    You can use windows authentication (which is what I needed). After including the following nuget packages in my code:

    Microsoft.TeamFoundationServer.Client
    Microsoft.VisualStudio.Services.Client
    Microsoft.VisualStudio.Services.InteractiveClient
    

    I was able to write this code:

    // Create instance of VssConnection using Windows credentials (NTLM)
    var connection = new VssConnection(new Uri("http://mytfsserver:8080/tfs/CollectionName"), new VssClientCredentials());
    
    // Create instance of WorkItemTrackingHttpClient using VssConnection
    var gitClient = connection.GetClient();
    var items = gitClient.GetRepositoriesAsync().Result;
    
    foreach (var item in items)
    {
        Console.WriteLine(item.Name);
    }
    

    See also: https://www.visualstudio.com/en-us/docs/integrate/get-started/client-libraries/samples

提交回复
热议问题