0
votes

I've been assigned to build a set of tools for DevOps for improving our turnaround time on building several branches. These tools will need to interact with our source control, which is currently running on Team Foundation Server. When I asked if we had access to Azure DevOps, which according to the tutorials I found online was needed to create an authentication token that could be used to access TFS through it's default REST API, I was told that we did not and had no plans to, because this company was an AWS organization.

Does anyone know if there's a way to access a REST or similar API for TFS if all you have access to is TFS running on AWS?

1
What version of TFS? You can create PATs in modern versions of TFS and use the same REST APIs you can use in Azure DevOps. TFS is just an on-prem installation of the same software that runs Azure DevOps. - Daniel Mann
Version 15.117.27024.0 is what we seem to be running. Do you know if I can create a PAT in that? I couldn't find any instructions to online. - wanderso
Yes. You have TFS 2017 Update 3. You can get a PAT by following the documentation; the UI may be different but the basic process should be the same: docs.microsoft.com/en-us/azure/devops/organizations/accounts/… - Daniel Mann
And before you ask: The TFS 2017 REST API documentation can be located here: docs.microsoft.com/en-us/azure/devops/integrate/previous-apis/… - Daniel Mann
Thank you, Daniel. - wanderso

1 Answers

3
votes

Yeah, as mentioned in the comment, you should use PAT to authenticate TFS through Rest API. Username should be blank. PAT is the password. There are multiple related tutorials in google, a sample for your refer:

using System.Net.Http;
using System.Net.Http.Headers;

...

//encode your personal access token                   
string credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken)));

ListofProjectsResponse.Projects viewModel = null;

//use the httpclient
using (var client = new HttpClient())
{
    client.BaseAddress = new Uri("https://{accountname}.visualstudio.com");  //url of our account
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials); 

    //connect to the REST endpoint            
    HttpResponseMessage response = client.GetAsync("_apis/projects?stateFilter=All&api-version=1.0").Result;

    //check to see if we have a succesfull respond
    if (response.IsSuccessStatusCode)
    {
        //set the viewmodel from the content in the response
        viewModel = response.Content.ReadAsAsync<ListofProjectsResponse.Projects>().Result;

        //var value = response.Content.ReadAsStringAsync().Result;
    }   
}

Since you are using PAT with on-premise TFS server, make sure you already turned off Basic Authentication on server. Otherwise you will get an returned error.

We recommend you keep IIS Basic Authentication turned off at all times when using Azure DevOps Server. Only if necessary should you enable IIS Basic Authentication. When IIS Basic Authentication is enabled on your windows machine, it prevents you from using personal access tokens (PATs) as an authentication mechanism.

Source link.

Moreover, we do have a good integration with AWS. We could call AWS services from Azure DevOps/TFS side. Also be able to use AWSCLI & AWS Powershell Module. In case you need, for more details please take a look at this link-- AWS Tools for Microsoft Visual Studio Team Services/TFS