0
   var tfsCredentials = new TfsClientCredentials(new Microsoft.TeamFoundation.Client.WindowsCredential(), true);
                TfsTeamProjectCollection teamCollection = new TfsTeamProjectCollection(new Uri(DomainConstants.BASE_ADDRESS), tfsCredentials);
                return teamCollection;

I used this for authenticate to TFS from current windows loggedin user and get TfsTeamProjectCollection, It is worked fine when it run from visual studio (localhost), but when I deployed my project in Server it occurs an error

An error occurred while processing your request

on browser and error log

Message :TF30063: You are not authorized to access http://unicorntfs:8080/tfs/USP.
StackTrace : at Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.SendRequest() at Microsoft.TeamFoundation.Client.Channels.TfsHttpRequestChannel.Request(TfsMessage message, TimeSpan timeout) at Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation operation, Object[] parameters, TimeSpan timeout, Object[]& outputs)
at Microsoft.TeamFoundation.Server.Classification.ListProjects() at Microsoft.TeamFoundation.Proxy.CommonStructureService.ListProjects()
at UnicornRMS.TimeManagement.Services.TFSTimeManagementServiceImpl.GetAllProjectsByUser(TfsTeamProjectCollection projCollection) at UnicornRSM.WEB.Controllers.TimeManagement.TimeManagementController.Index(Int32 weekNo)

How can I authenticate to TFS from current windows loggedin user

Thanks

1 Answers1

0

If you are connecting to a TFS server on your domain then you can use NetworkCredential to authenticate:

var _credentials = new NetworkCredential(UserName, Password);

TfsTeamProjectCollection server = new TfsTeamProjectCollection(_tfsUri, _credentials);

server.EnsureAuthenticated();

Moreover, try to delete your IE cache and cookies on your deployed server, then try it again.


Update

This issue may related to double hop. Some similar questions for your reference:

Community
  • 1
  • 1
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • I already have tried this way, thats worked fine. but I don't need to allow users to type and enter their username and password as they already logged in windows. any way thnks for reply @Patrick-MSFT – Sankha Sumadhura Jun 02 '16 at 06:58
  • Did you clean the user info which stored in Credential Manager on the server first? After this, it will pop up a TFS authentication window to enter UserName & Password – PatrickLu-MSFT Jun 02 '16 at 08:45
  • Double-Hop may be the root cause. The issue is not related to your code. I also find a related article for your reference: http://stackoverflow.com/questions/4013081/passthrough-impersonation-authentication-with-asp-net-and-tfs-api – PatrickLu-MSFT Aug 10 '16 at 02:49