TFS Authentication

Say you built an application that connects to TFS and you want a dialog box to appear if a user is not authorized to connect to TFS. To do this is quite simple.  There are two methods you might have seen when you are playing with the TeamFoundationServer object, Authenticate() and EnsureAuthenticated(). The difference between the two is Authenticate will always call the server and EnsureAuthenticated will only be called if the user has not already authenticated to the server. You should use the EnsureAuthenticated method as a performance point since you only want the call to go to the server if the user has not authenticated. Notice we are using the TeamFoundationServer constructor instead of the Factory; you can use the factory if you wish. The deciding point that you need to decide is if you want to reference the same object on subsequence calls and without the need to re-authenticate. Remember the factory method will return a cache instance of the object.


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



If the user presses cancel on the dialog box then a UnauthorizedException will be thrown ,so handle it gracefully.


Ed K.

Posted in TFS | VSX

(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview