Get SP Online list data using REST API for an External User

Andy 1,351 Reputation points
2023-01-05T05:31:17.16+00:00

How to get SharePoint Online list data using REST API for an external user ?

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-01-05T09:48:30.247+00:00

    Hi @Andy
    First , You need to get a binary security token, you need to use Microsoft Security Token Service, please enter the following URL:

    https://login.microsoftonline.com/extSTS.srf  
    

    Then ,needs to add following XML Envelope as a message body, replace [username], [password] & [yourdomain] with your data.Please set Content-Type to application/x-www-form-urlencoded in Request Header.

     <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">https://login.microsoftonline.com/extSTS.srf</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">  
          <o:UsernameToken>  
            <o:Username>[username]@[YourDomain].onmicrosoft.com</o:Username>  
            <o:Password>[Password]</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">  
            <a:EndpointReference>  
              <a:Address>https://[yourdomain].sharepoint.com/</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>  
    

    276388-image.png
    276452-image.png
    In the return request, you will get "BinarySecurityToken", please copy it and add it to the "body".you can send a POST request to the following URL ,finally you will get fedauth and rtfa cookies.

    https://[YourDomain].sharepoint.com/_forms/default.aspx?wa=wsignin1.0  
    

    276270-image.png

    We can get the request-digest value by sending a POST request to the below URL:

    https://yourdomain.sharepoint.com/_api/contextinfo  
    

    Add rtFa and FedAuth Cookie values as headers with the request.
    276360-image.png

    Finally you can connect to the SharePoint Rest Api by following parameters

    1. rtFa cookie
    2. FedAuth cookie
    3. X-Request-Digest

    276380-image.png

    Here is an issue similar with yours, please make a reference
    https://social.technet.microsoft.com/Forums/en-US/7899e714-b09c-42e3-b18e-7ca616d7e2f7/how-to-get-sp-online-list-data-using-rest-api-for-an-external-user?forum=onlineservicessharepoint


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.