0

When code run into line 2, Windows will show a popup to input username, password for TFS access:

TeamProjectCollection = new TfsTeamProjectCollection(new Uri(url), new UICredentialsProvider());
TeamProjectCollection.Connect(Microsoft.TeamFoundation.Framework.Common.ConnectOptions.IncludeServices);
TeamProjectCollection.EnsureAuthenticated();
IsConnected = true;

Have any way to assign username, password automatically without login from popup of windows.

Thanks.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
knowwebapp.com
  • 95
  • 4
  • 16
  • When it prompts for credentials, that means that the credentials that the process is running under do not have permission to the server. – Buck Hodges Mar 07 '13 at 13:50

1 Answers1

0

If you want to directly insert user credentials and not use the one the process is running, the following worked for me:

WindowsCredential credentials = new WindowsCredential(new NetworkCredential(username, domain, password), new MyCredentials(username, domain, password));
TfsTeamProjectCollection connectedTPC = new TfsTeamProjectCollection(tfsUrl, new TfsClientCredentials(credentials));

It's a bit strange to provide credentials two times, but without the MyCredentials I will get no answer from TFS, not sure why.

public class MyCredentials : ICredentialsProvider
{
    private NetworkCredential credentials;
    #region ICredentialsProvider Members
    public MyCredentials(string user, string domain, string password)
    {
        credentials = new NetworkCredential(user, password, domain);
    }

    public ICredentials GetCredentials(Uri uri, ICredentials failedCredentials)
    {
        return credentials;
    }

    public void NotifyCredentialsAuthenticated(Uri uri)
    {
        // who cares
    }

    #endregion
}
MikeR
  • 3,045
  • 25
  • 32