Welcome to MSDN Blogs Sign in | Join | Help

Impersonation / Authentication issues when using Integrated Windows Authentication and SharePoint

With Integrated Authentication its fairly often that people find themselves in a situation where the currently logged in users credentials are not passed from the client to a SQL server / File share / some other server that they are trying to access from SPS. I bumped into it myself and was tearing my hair apart till my colleague Walter Warren told me what the "Double-Hop Issue" was.

Though I’ve titled this blog under SharePoint this actually applies to ASP.NET as well. The problem I faced was that i was creating an ASP.NET web page that consumes the SharePoint Search web service. The ASP.NET app was hosted on a different IIS machine than SPS. The ASP.NET application had Integrated Windows Authentication turned on. All was fine when I was testing the ASP.NET page right from the server where IIS was running, however, when I tried running the same page from another workstation - I kept getting 401 - Unauthorized access errors.

This problem is due to Integrated Windows Authentication that’s turned on in IIS for the ASP.NET application virtual directory. The issue is known as the "Double Hop" issue - when we use Integrated Security, the user credentials are passed from the client system (in this case the different station) to the server that’s running IIS (in this case the ASP.NET application). When the IIS running the ASP.NET app makes a request to the SharePoint server (a second hop) it cannot pass the user credentials passed from the client system. This is a little known documented limitation in IIS, you can refer to a KB on http://support.microsoft.com/default.aspx?scid=kb;en-us;264921 (check the limitations section under Windows NT Challenge/Response - Integrated Windows Authentication was formerly named NTLM, or Windows NT Challenge/Response authentication).

There are 3 ways to workaround this problem

1) Turn of Windows Integrated Authentication and turn on Basic Authentication
2) Hardcode the credentials passed to SharePoint in the ASP.NET application code
3) Turn on Kerbrose Authentication

Option 1) Turn of Windows Integrated Authentication and turn on Basic Authentication

You can turn off Integrated Authentication and turn on Basic Authentication on the virtual directory running the ASP.NET application. With this you should be prompted for your user name and password every time you try to access the ASP.NET application and unlike Integrated Windows Authentication - your credentials are passed even in the second hop.

Note that the drawbacks of this option are
 i) in Basic Authentication the user credentials are passed as clear text
 ii) users will get a pop-up asking for user credentials every time they try to access your page.

Option 2) Pass user credentials using code

My code used the default credentials from the credential cache - however you can hardcode the credentials that are passed to SharePoint. In the SPS web service case i had to create a NetworkCredential object with the user credentials hardcoded and set the object to the Credentials property of the QueryService proxy object.

Changed the line from

 qs.Credentials = System.Net.CredentialCache.DefaultCredentials;

To
 qs.Credentials = new System.Net.NetworkCredential("<User Name", "<Password>", "<Domain Name>"); 

In the case of a Fileshare, etc - you will need to use an unmanaged API to impersonate the user on the SPS machine, here is an MSDN article to do that http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsIdentityClassImpersonateTopic.asp

You can alternatively instead of hardcoding the credentials in code - you can put them in the Web.Config file and retrieve at run time. If you do this - you should also encrypt the password.

Option 3) Turn on Kerberos Authentication

You need to turn on Kerberos on IIS and configure SharePoint for this - you can refer to this KB article for the exact steps http://support.microsoft.com/?id=832769

Any of these three options should resolve the problem.

Mohammed Jeelani

Published Tuesday, December 07, 2004 2:30 AM by mjeelani
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Notes For December 12

Sunday, December 12, 2004 10:42 PM by OdeToCode Link Blog

# Forms Authentication

Saturday, March 26, 2005 4:11 PM by Gianluca's Blog

# Forms Authentication

Saturday, March 26, 2005 4:38 PM by Gianluca's Blog

# Impersonation inside HttpHandlers

Monday, June 06, 2005 4:48 AM by Dion.ThoughtsContext.Current

# Impersonation inside HttpHandlers

Monday, June 06, 2005 4:49 AM by Dion.ThoughtsContext.Current

# Impersonation inside HttpHandlers

Monday, June 06, 2005 4:50 AM by Dion.ThoughtsContext.Current

# re: Impersonation / Authentication issues when using Integrated Windows Authentication and SharePoint

Friday, September 30, 2005 3:07 PM by Ali
Thank you. Well explained. Fixed the error i had :)

# All those hours of my life! Authentication issues with NTLM

Friday, February 10, 2006 6:35 PM by Point2Share
I have lost more hours of my life to the old &amp;ldquo;double hop&amp;rdquo; issue than almost any other. No...

# re: Impersonation / Authentication issues when using Integrated Windows Authentication and SharePoint

Saturday, February 11, 2006 12:59 AM by toast
Why wouldn't an organisation be using Kerberos whenever possible?

# How SharePoint 2003 makes users practice their passwords...

Tuesday, February 14, 2006 11:16 AM by spare thought
Hands up if you've seen this one with SharePoint 2003: you log on to your (SharePoint) site fine, then...

# Multi-hop authentication issues in Sharepoint (and elsewhere)

Tuesday, February 21, 2006 6:27 AM by Breaking Point Blog

# Multi-hop authentication issues in Sharepoint (and elsewhere)

Tuesday, February 21, 2006 6:33 AM by Breaking Point Blog

# re: Impersonation / Authentication issues when using Integrated Windows Authentication and SharePoint

Tuesday, March 21, 2006 12:21 PM by Arno van den Broek
I think this could resolve a number of issues with the famous explorer view as well. Keen to check that out or maybe somebody already experimented with this?

# online directory main

Tuesday, April 11, 2006 2:08 AM by online directory main
Welcome!!! http://www.dirare.com/Sweden/">http://www.dirare.com/Sweden/ online directory. [URL=http://www.dirare.com]YP national[/URL]: MY yellowpages, SMART Yellow Pages, About DIRare. Also [url=http://www.dirare.com]global directory[/url] from online directory .

# online directory main

Tuesday, April 11, 2006 2:08 AM by online directory main
hello! http://www.dirare.com/Sweden/ online directory. MY yellowpages, SMART Yellow Pages, About DIRare. From online directory .

# re: Impersonation / Authentication issues when using Integrated Windows Authentication and SharePoint

Friday, May 19, 2006 8:50 AM by Vimal
Good Article..

# re: Impersonation / Authentication issues when using Integrated Windows Authentication and SharePoint

Tuesday, June 06, 2006 7:59 AM by Craig
Excellent article.  Clear, detailed and well-explained.  What's pathetic is that the problem exists in the first place.

# Sharepoint asks me for my password every time I try and open a file after I log on.

Wednesday, October 18, 2006 7:38 PM by Caley's Blog

I have heard this complaint from many Sharepoint users. Well after some research it turns out it is a

# re: Impersonation / Authentication issues when using Integrated Windows Authentication and SharePoint

Friday, October 20, 2006 8:39 AM by katalog

good site

# My homepage

Thursday, November 16, 2006 9:29 AM by Freda

Great work!

[url=http://fhqjwnuj.com/krlp/rfno.html]My homepage[/url] | [url=http://nltiaoys.com/zclp/ozdg.html]Cool site[/url]

# My homepage

Saturday, November 18, 2006 3:37 AM by Zack

Thank you!

[url=http://fyspoied.com/vpgu/hjyq.html]My homepage[/url] | [url=http://aqsjebej.com/lgwa/ptzo.html]Cool site[/url]

# re: Impersonation / Authentication issues when using Integrated Windows Authentication and SharePoint

Thursday, March 15, 2007 1:41 AM by vinay

please tell me what technic is used in integrated windows authentication

# re: Impersonation / Authentication issues when using Integrated Windows Authentication and SharePoint

Thursday, November 15, 2007 12:13 AM by shekhar

please help me i am trying to upload the word documents from a seperate asp.net file to the document library under sharepoint even though i provide network credentials also i am getting the username password dialog box

# Mr.

Monday, January 14, 2008 2:28 PM by turystyka

I think this could resolve a number of issues with the famous explorer view as well. Keen to check that out or maybe somebody already experimented with this?

# Redirect to other page

Thursday, January 17, 2008 11:22 AM by Abdel-Rahman Awad

I am trying to pass the credintials from normal site to moss site how can the second step help me doing that please reply ! Abdel-Rahman@Live.com

# asp net windows impersonation

Wednesday, May 14, 2008 9:47 AM by asp net windows impersonation

# Problem with custom Web Service | keyongtech

Wednesday, January 21, 2009 10:24 PM by Problem with custom Web Service | keyongtech

# [SPS 2003] Transmission d'authentification au moteur de recherche | hilpers

# Mohammed Jeelani s Blog Impersonation Authentication issues when | Hair Growth Products

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker