簡體   English   中英

從 ADFS 聲明授權

[英]Claim auth from ADFS

我嘗試通過 WPF 應用程序連接到 SharePoint Online 實例。 我發現這篇文章描述了一種可能的解決方案,但問題是特定實例前面有一個 Active Directory 聯合身份驗證服務 (ADFS),我不知道如何獲取身份驗證令牌。 (我無法為我的應用程序創建證書以針對 adfs 進行身份驗證。)

任何已經完成此操作並且可以通過一些代碼片段支持我的人?

我玩過提琴手。 基本上流程是這樣的:

  • 從 ADFS 獲取 SAML 令牌
  • 將其發布到https://login.microsoftonline.com/login.srf (正文應為wa=wsignin1.0, wresult=<requestsecuritytokenresponse>…token…</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

我找到了解決方案並發表了一篇關於它的文章。 我也把它放在了github 上 您可以在的博客上找到我的博文以及 github 鏈接。

我希望這能像幫助我一樣幫助你:-)

我花了很多時間終於弄明白了。 為了獲得二進制令牌,您需要將以下格式的消息發布到 Microsoft Online Security Token Service (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
[斷言]:是您從聯邦服務獲得的斷言 XLM 令牌。

從響應 XML 中獲取t=...二進制標記后,您可以將其發布到 SP default.aspx以獲取 cookie。

對於遇到麻煩的人(真的很難),這里有一些澄清

這 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...... .... 那就是整個身體,沒有別的。 它會生成一些cookie。 一個用於 myshare.sharepoint.com,稱為 FedAuth,另一個用於 sharepoint.com rtFa

第四步,一旦你得到cookies,你就可以得到你的sharepoint列表

https://myshare.sharepoint.com/sites/mysite/_api/Web/Lists/GetByTitle('Updating%20List%E2%80%8B')/items

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM