title: Authenticating to SharePoint Online using cURL (using ADFS 2.1 as IP-STS)
body: <p>I'm trying to set up a simple script that uses cURL to monitor our SharePoint Online site by doing the following:-</p>
  
  <ol>
  <li>Log into our Office 365 environment using a federated identity (ADFS 2.1) using the "../adfs/services/trust/13/UsernameMixed" endpoint</li>
  <li>Obtain SharePoint cookies (FedAuth etc)</li>
  <li>Browse to SharePoint site (verify content etc)</li>
  </ol>
  
  <p>To do the first step, I'm using cURL to do submit the following POST to our ADFS endpoint:</p>
  
  <pre><code>curl https://sts.contoso.com/adfs/services/trust/13/UsernameMixed --data @req.txt -H "Content-Type: application/soap+xml" -o out.txt
  </code></pre>
  
  <p>The SOAP envelope I am sending is requesting the following (this is just an extract of the request):</p>
  
  <pre><code>&lt;trust:RequestSecurityToken xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512"&gt;
      &lt;wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"&gt;
          &lt;a:EndpointReference&gt;
              &lt;a:Address&gt;https://login.microsoftonline.com/extSTS.srf&lt;/a:Address&gt;
          &lt;/a:EndpointReference&gt;
      &lt;/wsp:AppliesTo&gt;
      &lt;trust:KeyType&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer&lt;/trust:KeyType&gt;
      &lt;trust:RequestType&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue&lt;/trust:RequestType&gt;
      &lt;trust:TokenType&gt;urn:oasis:names:tc:SAML:1.0:assertion&lt;/trust:TokenType&gt;
  &lt;/trust:RequestSecurityToken&gt;
  </code></pre>
  
  <p></p>
  
  <p>The response I get back from this contains an X509 certificate, a digest and a signature which I do not know what to with.  All the guides I can see online result in a "BinarySecurityToken" being returned from this initial request which you can extract and post to Sharepoint.com to get the necessary cookies to gain access.  Admittedly they are all using the MicrosoftOnline STS though (cloud credentials) so is this just something that the Microsoft STS can achieve but not ADFS servers?</p>
  
  <p>Or is there something glaringly wrong in my approach?</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Cheers,</p>
  
  <p>Duncan</p>