Romonov
Romonov

Reputation: 8605

Accessing TFS endpoint programmatically

I am trying to access a TFS endpoint using the following code:

Uri collectionUri = new Uri("https://tfsendpoint.com:8443");
NetworkCredential networkCredential = new NetworkCredential(<username>, <password>);
WindowsCredential windowsCredential = new WindowsCredential(networkCredential);
TfsClientCredentials tfsClientCredentials = new TfsClientCredentials(windowsCredential);
tfsClientCredentials.AllowInteractive = false;
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri, tfsClientCredentials);
tpc.Authenticate();
WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();

But the tpc.Authenticate() is throwing a 403 Forbidden error. When I access the same endpoint(https://tfsendpoint.com:8443) through a browser, it is popping up a UI window to enter a username and password. Once entered, it is logging in and allowing access to the TFS items.

Wondering what changes are needed in the code to allow the programmatic login to go through. I tried BasicAuthCredential, SimpleWebTokenCredential. But getting the same 403 Forbidden result.

Upvotes: 1

Views: 131

Answers (1)

Isaiah4110
Isaiah4110

Reputation: 10120

Change the collection URL to this format:

Uri collectionUri = new Uri("http://tfsserver:8080/tfs/collectionname");

Upvotes: 1

Related Questions