无法使用联合服务以编程方式对SharePoint Online进行身份验证

时间:2014-05-05 13:09:39

标签: sharepoint federated-identity sharepoint-online

我无法使用SharePointOnlineCredentials对SharePoint Online进行身份验证,并收到错误消息:

Identity Client运行时库(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: 

3 个答案:

答案 0 :(得分:7)

我通过确保在代码中使用SharePoint Online客户端组件来解决了这个问题。以下是我采取的步骤:

  1. 卸载了SharePoint Online Management Shell(http://www.microsoft.com/en-us/download/details.aspx?id=35588)。原始程序是去年秋天编写的,是作为PowerShell程序的扩展而开始的,它使用了SharePoint Online Management Shell附带的Microsoft.Online.SharePoint.Client.Tenant.dll。该程序应引用C:\ Program Files \ SharePoint Client Components \ 16.0 \ Assemblies \ Microsoft.Online.SharePoint.Client.Tenant.dll。

  2. 安装了最新的SharePoint Online Client Components SDK(http://www.microsoft.com/en-us/download/details.aspx?id=42038)。请务必注意,此SDK与SharePoint 2013客户端组件SDK不同。 SharePoint Online Client组件SDK是版本16; SharePoint 2013客户端组件SDK是版本15.

  3. 确保从Web Server Extensions文件夹中的16版本加载的程序中的Microsoft.SharePoint.Client和Microsoft.SharePoint.Client.Runtime dll,例如C:\ Program Files \ Common Files \ Microsoft Shared \ Web Server Extensions \ 16 \ ISAPI \ Microsoft.SharePoint.Client.dll。

  4. 我现在可以使用联合帐户和非联合帐户进行身份验证。

答案 1 :(得分:1)

Maximilian,您可以使用以下内容添加它们:

$spoClientAssemblies = 
'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll',
'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'

foreach($reqAssembly in $spoClientAssemblies)
{
    Add-Type -LiteralPath $reqAssembly -ErrorAction:Continue
}

您还可以检查dll的当前域的程序集。

[AppDomain]::CurrentDomain.GetAssemblies()

答案 2 :(得分:0)

您需要确保在脚本的开头加载所需的SharePoint Online程序集

Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll" 

Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"