0

I have created one console app which connect to tfs server using windows authentication. I have upload this app in azure web jobs but while executing it is showing authentication error. How to use my windows authentication on azure web job. I have tried below code but it is not working.

NetworkCredential credentials = new NetworkCredential("UserName", "PAssword","Domain");

                TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(serverName), credentials);
                tpc.Authenticate();
  • What's your TFS version? – PatrickLu-MSFT Nov 25 '19 at 09:36
  • Hi Dharmesh Patel,Did you get a chance to implement the solution that I suggested? Were you able to resolve? If my reply helped or gave a right direction. Appreciate for [marking it as an answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) which will also help others in the community. – PatrickLu-MSFT Nov 27 '19 at 10:17

1 Answers1

0

For TFS 2015 and above version, to connect to TFS using specific credentials, you could refer below code snippet:

To connect to TFS using specific credentials:

// For TFS 2015 & above
// Ultimately you want a VssCredentials instance so... 
NetworkCredential netCred = new NetworkCredential(@"user.name", @"Password1", "DOMAIN");
WindowsCredential winCred = new WindowsCredential(netCred);
VssCredentials vssCred = new VssClientCredentials(winCred);

// Now you can connect to TFS passing Uri and VssCredentials instances as parameters   
Uri tfsUri = new Uri(@"http://tfs:8080/tfs");
var tfsTeamProjectCollection = new TfsTeamProjectCollection(tfsUri, vssCred);

// Finally, to make sure you are authenticated...
tfsTeamProjectCollection.EnsureAuthenticated();

Besides, you could also choose to use PAT token, if you are using TFS2017 and above. Especially basic authentication blocked on some repositories or environment . Just create Personal Access Token (PAT) in the repository. Then use that in your connections to access TFS.

More details please take a look at C.J's answer in this case: Connect to TFS programmatically from vs 2017

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62