15

我尝试通过 WPF 应用程序连接到 SharePoint Online 实例。我发现这篇文章描述了一个可能的解决方案,但问题是特定实例前面有一个 Active Directory 联合身份验证服务 (ADFS),我不知道如何获取身份验证令牌。(我无法为我的应用程序创建证书以针对 adfs 进行身份验证。)

任何已经这样做并且可以通过一些代码片段支持我的人吗?

4

4 回答 4

9

我和 Fiddler 一起玩过。基本上流程是这样的:

  • 从 ADFS 获取 SAML 令牌
  • 将其发布到https://login.microsoftonline.com/login.srf(正文应该是wa=wsignin1.0, wresult=<requestsecuritytokenresponse>…token…&lt;/rstr> and wctx=MEST=0&LoginOptions=2&wa=wsignin1%2E0&rpsnv=2&ct=1343219880&rver=6%2E1%2E6206%2E0&wp=MBI&wreply=https%3A%2F%2Fspirit365%2Esharepoint%2Ecom%2F%5Fforms%2Fdefault%2Easpx&id=500046&cbcxt=mai&wlidp=1&guest=1&vv=910&mkt=EN-US&lc=1033&bk=1343219930
  • 从表单中捕获名为“t”的隐藏输入
  • 将该“t”发布到 /_layouts/Authenticate.aspx。那应该给你 FedAuth 和 rtFa cookie。

从那时起,这与此处的代码相同:http: //www.wictorwilen.se/Post/How-to-do-active-authentication-to-Office-365-and-SharePoint-Online.aspx

于 2012-07-25T14:14:30.853 回答
6

我找到了解决方案并发表了一篇关于它的帖子。我也把它放在了github 上您可以在我的博客中找到我的博客文章以及 github 链接。

我希望这对你有帮助,就像它对我有帮助一样:-)

于 2013-01-04T03:34:54.080 回答
4

我花了很多时间终于弄明白了。为了获取二进制令牌,您需要将以下格式的消息发布到 Microsoft 在线安全令牌服务 (STS) 站点 URL:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <a:To s:mustUnderstand="1">[toUrl]</a:To>
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      [assertion]
    </o:Security>
  </s:Header>
  <s:Body>
    <t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
      <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
        <a:EndpointReference>
          <a:Address>[url]</a:Address>
        </a:EndpointReference>
      </wsp:AppliesTo>
      <t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>
      <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
      <t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType>
    </t:RequestSecurityToken>
  </s:Body>
</s:Envelope>

需要此消息以将令牌替换为以下值:

[toUrl]:Microsoft 在线安全令牌服务 (STS) 站点 URL。
[url]:您的 SP 站点 URL
[assertion]:是您从联合服务获得的断言 XLM 令牌。

从响应 XML 中获取t=...二进制令牌后,您可以将其发布到您的 SPdefault.aspx以获取 cookie。

于 2014-12-02T21:31:50.947 回答
0

对于任何有麻烦的人(真的很难),这里有一些澄清

这 4 个步骤是 1)从您的 SAML IDP 获取断言 2)将断言交易为 STS 令牌 3)将 STS 令牌交易为 cookie 4)使用 cookie 进行休息调用

对于第 1 步,我有 ping federate。在邮递员中使用它来发布到您的令牌 ID 处理器以获得断言:POST https://pingfederate/idp/sts.wst?TokenProcessorId=username

<s:Envelope xmlns:s='http://www.w3.org/2003/05/soap-envelope' xmlns:a='http://www.w3.org/2005/08/addressing' xmlns:u='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>
    <s:Header>
        <a:Action s:mustUnderstand='1'>http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
        <a:ReplyTo>
            <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
        </a:ReplyTo>
        <o:Security s:mustUnderstand='1' xmlns:o='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>
            <o:UsernameToken>
                <o:Username>yourusername</o:Username>
                <o:Password>yourpass</o:Password>
            </o:UsernameToken>
        </o:Security>
    </s:Header>
    <s:Body>
        <t:RequestSecurityToken xmlns:t='http://schemas.xmlsoap.org/ws/2005/02/trust'>
            <wsp:AppliesTo xmlns:wsp='http://schemas.xmlsoap.org/ws/2004/09/policy'>
                <wsa:EndpointReference xmlns:wsa='http://www.w3.org/2005/08/addressing'>
                    <wsa:Address>urn:federation:MicrosoftOnline</wsa:Address>
                </wsa:EndpointReference>
            </wsp:AppliesTo>
            <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
        </t:RequestSecurityToken>
    </s:Body>
</s:Envelope>

它将生成一个包含断言的信封。确保以原始格式(不是漂亮的 xml)复制它。从 <saml:Assertion 到 /saml:Assertion> 的所有内容

对于第 2 步,当您 POST 到https://login.microsoftonline.com/extSTS.srf时,请确保以原始格式(不是漂亮的 XML)粘贴断言。

采用:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <saml:Assertion AssertionID="hp4CtHjK_lL" Issue Instant...................../ds:Signature></saml:Assertion>
    </o:Security>
  </s:Header>
  <s:Body>
    <t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
      <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
        <a:EndpointReference>
          <a:Address>https://myshare.sharepoint.com/sites/mysite</a:Address>
        </a:EndpointReference>
      </wsp:AppliesTo>
      <t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>
      <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
      <t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType>
    </t:RequestSecurityToken>
  </s:Body>
</s:Envelope>

对于第 3 步,POST 到https://myshare.sharepoint.com/_forms/default.aspx?wa=wsignin1.0并确保您的 User-Agent 是常规用户代理,如 Mozilla/5.0(兼容;MSIE 9.0 ;Windows NT 6.1;Win64;x64;Trident/5.0)。在帖子的正文中,它将是第 2 步生成的 <BinarySecurityToken 中的所有内容,因此类似于 t=EwDgAk6hBwAUu3 ...... .... 那是整个身体,没有别的。它会生成一些cookies。一个用于 myshare.sharepoint.com,称为 FedAuth,另一个是 sharepoint.com rtFa

第 4 步,获得 cookie 后,您可以获取您的共享点列表

https://myshare.sharepoint.com/sites/mysite/_api/Web/Lists/GetByTitle('Updating%20List%E2%80%8B')/items
于 2021-03-17T22:10:47.317 回答