title: Connect to SharePoint Online using an external user using c# and Client Side Object Model (CSOM)
body: <p>I'm trying to connect to SharePoint Online website using c# and Client Side Object Model (CSOM). I'm an external user and can access the URL using my browser but when I try that programmatically, it fails saying - The sign-in name or password does not match one in the Microsoft account system. Following is the code sample that I have tried. I have the correct username/password. Any help is appreciated.</p>
  
  <p>To add clarity - my external user looks like       myemail#EXT#@companyname.onmicrosoft.com  (the @ sign inmyemail is replaced with an underscore). </p>
  
  <pre><code>string siteUrl = "https://companyname.sharepoint.com/sites/ERCT";
  using (ClientContext clientContext = new ClientContext(siteUrl))
  {
      var psd = "Password".ToCharArray();
      SecureString secureString = new SecureString();
      foreach (char c in psd) secureString.AppendChar(c);
      //psd.ToList().ForEach(secureString.AppendChar);
  
      clientContext.Credentials = new SharePointOnlineCredentials("username@companyname.onmicrosoft.com", secureString);
      SP.List oList = clientContext.Web.Lists.GetByTitle("ListName");
  
      CamlQuery camlQuery = new CamlQuery();
      camlQuery.ViewXml = "&lt;View&gt;&lt;RowLimit&gt;100&lt;/RowLimit&gt;&lt;/View&gt;";
  
      ListItemCollection collListItem = oList.GetItems(camlQuery);
  
      clientContext.Load(collListItem,
      items =&gt; items.Include(
          item =&gt; item.Id,
          item =&gt; item.DisplayName,
          item =&gt; item.HasUniqueRoleAssignments));
  
      clientContext.ExecuteQuery();
  
      foreach (ListItem oListItem in collListItem)
      {
          Console.WriteLine("ID: {0} \nDisplay name: {1} \nUnique role assignments: {2}",
          oListItem.Id, oListItem.DisplayName, oListItem.HasUniqueRoleAssignments);
      }
  }
  </code></pre>