title: SharePoint Online authentication failure
body: <p>I have a C# app which authenticates to SharePoint Online by using web requests. It works great for me, but someone else is getting the following error:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;&lt;S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:psf="http://schemas.microsoft.com/Passport/SoapServices/SOAPFault"&gt;
    &lt;S:Body&gt;
      &lt;S:Fault&gt;
        &lt;S:Code&gt;
          &lt;S:Value&gt;S:Sender&lt;/S:Value&gt;
          &lt;S:Subcode&gt;
            &lt;S:Value&gt;wst:FailedAuthentication&lt;/S:Value&gt;
          &lt;/S:Subcode&gt;
        &lt;/S:Code&gt;
        &lt;S:Reason&gt;
          &lt;S:Text xml:lang="en-US"&gt;Authentication Failure&lt;/S:Text&gt;
        &lt;/S:Reason&gt;
        &lt;S:Detail&gt;
          &lt;psf:error&gt;
            &lt;psf:value&gt;0x80048821&lt;/psf:value&gt;
            &lt;psf:internalerror&gt;
              &lt;psf:code&gt;0x80041034&lt;/psf:code&gt;
              &lt;psf:text&gt;The specified member name is either invalid or empty.&amp;#x000D;&amp;#x000A;&lt;/psf:text&gt;
            &lt;/psf:internalerror&gt;
          &lt;/psf:error&gt;
        &lt;/S:Detail&gt;
      &lt;/S:Fault&gt;
    &lt;/S:Body&gt;
  &lt;/S:Envelope&gt;
  </code></pre>
  
  <p><strong>What does this error mean? I'm pretty sure they are entering the correct username and password. Is there a list of SharePoint Online error codes I can find somewhere that would help me identify the problem?</strong></p>
  
  <p>Here's my C# code:</p>
  
  <pre><code>var request = (HttpWebRequest)WebRequest.Create(@"https://login.microsoftonline.com/extSTS.srf");
  request.AllowAutoRedirect = false;
  request.ContentType = @"application/json; odata=verbose";
  request.CookieContainer = this.CookieContainer;
  request.Method = @"POST";
  request.UserAgent = @"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
  
  string soapRequest = Strings.SharePointOnlineAuthenticationRequest
      .Replace(@"$(UserName)", this.UserName)
      .Replace(@"$(Password)", this.Password)
      .Replace(@"$(Address)", this.SiteUrl);
  byte[] contentBytes = new ASCIIEncoding().GetBytes(soapRequest);
  request.ContentLength = contentBytes.Length;
  using (var requestStream = request.GetRequestStream())
  {
      requestStream.Write(contentBytes, 0, contentBytes.Length);
  }
  </code></pre>
  
  <p><strong>Strings.SharePointOnlineAuthenticationRequest</strong></p>
  
  <p>This is the SOAP request I am sending. The "$(UserName)", "$(Password)", and "$(Address)" tokens are replaced at runtime.</p>
  
  <pre><code>&lt;value&gt;
    &lt;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"&gt;
    &lt;s:Header&gt;
    &lt;a:Action s:mustUnderstand="1="&gt;http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue&lt;/a:Action&gt;
    &lt;a:ReplyTo&gt;
    &lt;a:Address&gt;http://www.w3.org/2005/08/addressing/anonymous&lt;/a:Address&gt;
    &lt;/a:ReplyTo&gt;
    &lt;a:To s:mustUnderstand="1="&gt;https://login.microsoftonline.com/extSTS.srf&lt;/a:To&gt;
    &lt;o:Security s:mustUnderstand="1=" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;
    &lt;o:UsernameToken&gt;
    &lt;o:Username&gt;$(UserName)&lt;/o:Username&gt;
    &lt;o:Password&gt;$(Password)&lt;/o:Password&gt;
    &lt;/o:UsernameToken&gt;
    &lt;/o:Security&gt;
    &lt;/s:Header&gt;
    &lt;s:Body&gt;
    &lt;t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust"&gt;
    &lt;wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"&gt;
    &lt;a:EndpointReference&gt;
    &lt;a:Address&gt;$(Address)&lt;/a:Address&gt;
    &lt;/a:EndpointReference&gt;
    &lt;/wsp:AppliesTo&gt;
    &lt;t:KeyType&gt;http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey&lt;/t:KeyType&gt;
    &lt;t:RequestType&gt;http://schemas.xmlsoap.org/ws/2005/02/trust/Issue&lt;/t:RequestType&gt;
    &lt;t:TokenType&gt;urn:oasis:names:tc:SAML:1.0:assertion&lt;/t:TokenType&gt;
    &lt;/t:RequestSecurityToken&gt;
    &lt;/s:Body&gt;
    &lt;/s:Envelope&gt;
  &lt;/value&gt;
  </code></pre>