TFS API Part 13: More About Connecting TFS (Custom Credentials, Prompt)

10/02/2009

one comment

TFS API Part 13: More About Connecting TFS (Custom Credentials, Prompt)

I got many request regarding TFS Connection,

  1. How to connect TFS with Different User name?
  2. How to set default user name & password?
  3. How to prompt Credentials for TFS?

So Here it is.

In TFS API Part 1: Domain Picker we saw how to connect TFS using Domain Picker that makes the connect to TFS very easy, But some times we just want to take the TFS server from our Cache (TFS API Part 2: Domain Picker Using Registered Servers (Cache)) and save time.

Example 1 – Make Sure User Can Authenticate With TFS

//Cache Instance
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(TFSNAME);

OR
//New Instance

TeamFoundationServer tfs = new TeamFoundationServer(TFSNAME);


//Make sure that the current user has enough permissions to connect TFS, if not an exception is raised.

tfs.EnsureAuthenticated();

 

Example 2 – Prompt for Credentials

//If the current user don’t have enough permissions then a connection dialog will be displayed

//when EnsureAuthenticated is called below

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(TFSNAME,new UICredentialsProvider());

OR

TeamFoundationServer tfs = new TeamFoundationServer(TFSNAME,new UICredentialsProvider());

 

tfs.EnsureAuthenticated();

 

Example 3 – Custom Credentials

//Connect TFS with Custom credentials

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(TFSNAME,new NetworkCredential(username,password,domain));

OR

TeamFoundationServer tfs = new TeamFoundationServer(TFSNAME,new NetworkCredential(username,password,domain));

tfs.EnsureAuthenticated();

 

Example 4 – Custom Credentials With Ability to Prompt

//If the custom credential is not valid a connection dialog will displayed.

TeamFoundationServer tfs = new TeamFoundationServer(TFSNAME, new NetworkCredential(username, password, domain), new UICredentialsProvider());

Add comment
facebook linkedin twitter email

Leave a Reply

one comment

  1. Kunal Gujar02/06/2011 ב 18:01

    Great aritcles on tfs api…