DCSIMG
TFS API Part 13: More About Connecting TFS (Custom Credentials, Prompt) - Shai Raiten's Blog

Shai Raiten's Blog

It's all about code...

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

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());

Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# February 11, 2009 10:49 AM

Shai Raiten said:

TFS API Summary & My #200 Post It’s been 4 months, 3 weeks(143 days) since my ..::: My #100 Post

# February 13, 2009 11:44 PM

Kunal Gujar said:

Great aritcles on tfs api...

# June 2, 2011 6:01 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: