Я не могу пройти аутентификацию в SharePoint Online с помощью SharePointOnlineCredentials, получая сообщение об ошибке:
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: