我无法使用 SharePointOnlineCredentials 对 SharePoint Online 进行身份验证,收到错误消息:
Identity Client Runtime Library (IDCRL) 在与合作伙伴 STS 通信时遇到错误。
在我们实施 AD FS 以将身份验证联合到我们的 Active Directory 之前,相同的代码一直有效。而且,事实上,当我访问我自己的不使用联合服务的个人 SharePoint Online 网站时,该代码仍然有效。这使我怀疑将 SharePointOnlineCredential 与联合服务一起使用时存在问题。
任何人都可以确认是这种情况吗?如果是这样,解决方法是什么?
我创建了一个简单的程序来验证这个问题,如下所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.Online.SharePoint.Client;
using System.Security;
namespace SPOConsole
{
class Program
{
static void Main(string[] args)
{
var targetSite = new Uri("<https://<mydomain>.sharepoint.com>");
var login = "<myuserid>@<mydomain>.com";
var password = "<mypassword>";
var securePassword = new SecureString();
foreach (char c in password)
{
securePassword.AppendChar(c);
}
var onlineCredentials = new SharePointOnlineCredentials(login, securePassword);
using (ClientContext clientContext = new ClientContext(targetSite))
{
clientContext.Credentials = onlineCredentials;
Web web = clientContext.Web;
clientContext.Load(web,
webSite => webSite.Title);
clientContext.ExecuteQuery();
Console.WriteLine(web.Title);
Console.Read();
}
}
}
}
代码失败就行了:
var onlineCredentials = new SharePointOnlineCredentials(login, securePassword);
以下是堆栈跟踪:
Microsoft.SharePoint.Client.IdcrlException was unhandled
HResult=-2147186451
Message=Identity Client Runtime Library (IDCRL) encountered an error while talking to the partner STS.
Source=Microsoft.SharePoint.Client.Runtime
ErrorCode=-2147186451
StackTrace:
at Microsoft.SharePoint.Client.Idcrl.ManagedIdcrl.CheckHResult(Int32 hr)
at Microsoft.SharePoint.Client.Idcrl.ManagedIdcrl.LogonIdentity(String username, SecureString password)
at Microsoft.SharePoint.Client.Idcrl.SharePointOnlineAuthenticationProvider.Logon(String username, SecureString password)
at Microsoft.SharePoint.Client.SharePointOnlineCredentials..ctor(String username, SecureString password)
at SPOConsole.Program.Main(String[] args) in c:\Users\michael.norton\Documents\Visual Studio 2012\Projects\SimpleSPOConnection\SPOConsole\Program.cs:line 26
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: