我有一个Web API,该Web API正在通过Windows身份验证被有角度的Web应用程序调用。我需要使用通过Windows身份验证传递的凭据才能进入共享点api。
以下是我当前拥有的代码的示例。 (请注意,...表示我已省略一些代码的地方,还有更多使用方法,我不认为为此需要在Sharepoint上执行的操作的代码。)
using Microsoft.SharePoint.Client.Utilities;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Http;
using System.Security.Claims;
using Microsoft.SharePoint.Client;
using System.Web;
using SP = Microsoft.SharePoint.Client;
using System.Security.Principal;
using System.Net;
...
public static List<SPDocument> GetSPDocumentsById(int itemId)
{
using (ClientContext context = new ClientContext("https://...")
{
//This I believe is giving me the IIS user Identity, and not the Windows
//credentials that the user is logging into the API with.
context.Credentials = CredentialCache.DefaultNetworkCredentials;
...
}
}
我的问题与该问题中的问题非常相似:IIS Application Pool Identity to use Logged On User Windows Identity,但是解决此问题的步骤不能解决我的问题。在控制器内是否检查HttpContext.Current.User.Identity.Name
我获得了期望的用户名,但是如果我选中WindowsIdentity.GetCurrent().Name;
,我将获得IIS用户帐户。如果WindowsIdentity.GetCurrent().Name;
调用返回了已登录的用户Windows帐户,则可以解决我的问题。
答案 0 :(得分:0)
事实证明,这是本文(https://blogs.technet.microsoft.com/askds/2008/06/13/understanding-kerberos-double-hop/)中所述的Kerbos双跳问题,为了解决此问题,我们仅将api与尝试访问的其他资源移到了同一服务器上。