【问题标题】:Authenticating domain users to SharePoint Online via ADFS通过 ADFS 向 SharePoint Online 验证域用户
【发布时间】:2017-04-18 07:33:14
【问题描述】:

我需要编写一个 C# 应用程序,该应用程序将连接到 SharePoint Online 文档库并允许用户从库中导入内容(文档库正在替换旧的网络驱动器)。我们的 Office 365 租赁使用本地 ADFS 服务器(完全联合身份)提供的 SSO 进行身份验证。

我在想,为了连接到文档库,我需要从 ADFS 服务器请求某种授权令牌,以便在连接到文档库时传递到 SharePoint Online 的登录 URL。不过,我以前从来没有做过这样的事情,所以我想知道这里是否有人做过类似的事情,或者对从哪里开始有什么好的建议?该应用程序只会在加入域的机器上运行,因此无需考虑离线场景。

非常感谢您的任何建议!

【问题讨论】:

    标签: c# authentication sharepoint office365 adfs


    【解决方案1】:

    您的应用程序需要的是 o365 会话 cookie,因此 Sharepoint 允许您使用文档库。

    你应该看看这里: Remote Authentication in SharePoint Online Using Claims-Based Authentication

    基本上,这个想法是在您的应用程序中打开一个隐藏的网络浏览器。您调用您的 Sharepoint 站点,o365 重定向到您的 ADFS 进行身份验证,blablabla 标准身份验证过程发生。

    身份验证过程完成后,Sharepoint 会发出一个名为“FedAuth”的会话 cookie(onprem,它可能在 o365 中有另一个名称)。您从网络浏览器中提取此 cookie,并使用它来调用您的 Sharepoint 在线站点(一旦您拥有 cookie,您就可以“处置”网络浏览器)。

    【讨论】:

      【解决方案2】:

      我设法让 ADFS 使用此代码颁发令牌:

          public GenericXmlSecurityToken GetToken()
          {
              WS2007HttpBinding binding = new WS2007HttpBinding(SecurityMode.Transport);
              binding.Security.Message.EstablishSecurityContext = false;
              binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
              WSTrustChannelFactory factory = new WSTrustChannelFactory((binding), new EndpointAddress(stsEndpoint));
              factory.TrustVersion = TrustVersion.WSTrustFeb2005;
              factory.Credentials.SupportInteractive = false;
              var rst = new RequestSecurityToken
              {
                  RequestType = RequestTypes.Issue,
                  AppliesTo = new EndpointReference(realm),
                  KeyType = KeyTypes.Bearer
              };
              IWSTrustChannelContract channel = factory.CreateChannel();
              return channel.Issue(rst) as GenericXmlSecurityToken;
          }
      

      然后将其用于参数化我提交给 MS STS 服务器以进行身份​​验证的 SOAP 请求。完成后,我可以使用 HttpWebRequest 和 CookieContainer 从 SharePoint 获取 cookie,然后我使用此代码

          [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
          private static extern bool InternetSetCookie(string url, string name, string data);
      

      公开 InternetSetCookie 方法以保存用户会话的 cookie。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-05-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-16
        • 1970-01-01
        相关资源
        最近更新 更多