views:

40

answers:

2

I'm trying to enable passthrough or impersonation authentication inside an ASP.NET website that uses the TFS2010 API.

I've got this working correctly with Cassini, however with IIS 7.5 (Windows 7) something is going wrong.

I found this blog post on the subject, and tried the following:

private static void Test()
{
    TfsTeamProjectCollection baseUserTpcConnection = 
            new TfsTeamProjectCollection(new Uri(Settings.TfsServer));

    // Fails as 'baseUserTpcConnection' isn't authenticated
    IIdentityManagementService ims = 
            baseUserTpcConnection.GetService<IIdentityManagementService>();

    // Read out the identity of the user we want to impersonate
    TeamFoundationIdentity identity = ims.ReadIdentity(
            IdentitySearchFactor.AccountName, 
            HttpContext.Current.User.Identity.Name,
            MembershipQuery.None, 
            ReadIdentityOptions.None);

    TfsTeamProjectCollection impersonatedTpcConnection = new 
            TfsTeamProjectCollection(new Uri(Settings.TfsServer), 
            identity.Descriptor);
}

When I use Cassini nothing is needed besides

collection = new TfsTeamProjectCollection(new Uri(server));

I have enabled the web.config settings (and have the Windows Auth module installed):

<authentication mode="Windows"/>
<identity impersonate="true" />

Is there something obvious that I've missed out?

+3  A: 

I wonder if you're hitting the old Double-Hop issue here?

Paul Nearney
Most likely the double-hop thing.
Robaticus
I am, but the new APIs in 2010 are meant to get around this (the Test method)
Chris S
There's no "getting around" the double hop issue unless you deploy Kerberos. Your solution works in Cassini because the Web Dev Server is running as "you" whereas IIS is running as a service account.
Jim Lamb
You get my vote but I'm being pedantic and saying this is the reason rather than the solution :) From reading that article configuring kerberos delegation wouldn't be a trivial task just for my app.
Chris S
Going from memory (and it was a couple of years ago) - I think its just a setting against the server in AD (Trust for Delegation?) - assuming your network is already running Kerberos - and if not, why not ;o)
Paul Nearney
A: 

The easiest solution to this problem as I've discovered, is to simply run your application under the TFS:8080 site, as a new application. The hop issue is then removed as you are running in the same context as the web service that your app is calling.

  • Create a new app pool, use network identity.
  • Make sure your application has anonymous authentication turned off
  • Make sure it has windows authentication turned on.
  • Add <identity impersonate="true" /> to the web config.
Chris S