Connect to SharePoint Online using an external user using c# and Client Side Object Model (CSOM)

sharepoint online csom authentication
modern authentication sharepoint online c#
sharepoint client object model
connect to sharepoint online c#
send email using sharepoint client object model c#
sharepoint online csom oauth
get sharepoint list items programmatically c#
sharepoint online csom c#

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.

To add clarity - my external user looks like (the @ sign inmyemail is replaced with an underscore).

string siteUrl = "";
using (ClientContext clientContext = new ClientContext(siteUrl))
    var psd = "Password".ToCharArray();
    SecureString secureString = new SecureString();
    foreach (char c in psd) secureString.AppendChar(c);

    clientContext.Credentials = new SharePointOnlineCredentials("", secureString);
    SP.List oList = clientContext.Web.Lists.GetByTitle("ListName");

    CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml = "<View><RowLimit>100</RowLimit></View>";

    ListItemCollection collListItem = oList.GetItems(camlQuery);

    items => items.Include(
        item => item.Id,
        item => item.DisplayName,
        item => item.HasUniqueRoleAssignments));


    foreach (ListItem oListItem in collListItem)
        Console.WriteLine("ID: {0} \nDisplay name: {1} \nUnique role assignments: {2}",
        oListItem.Id, oListItem.DisplayName, oListItem.HasUniqueRoleAssignments);

I've tried your code and it works fine on my tenancy. I installed the "Microsoft.SharePointOnline.CSOM" nuget package. Maybe try:

uninstall-package "Microsoft.SharePointOnline.CSOM"
install-package "Microsoft.SharePointOnline.CSOM"

Also, try running this in a new Console App. Depending on your app.config there maybe settings around proxies etc.

If that doesn't help you could also try fiddler to watch the calls.

EDIT: Also try using the email address of the external user by itself as the login name.

Get started using the client object model with external data in , Learn how to use the SharePoint client object model to work with on OData sources and using that data in SharePoint or Office 2013 components. The following are some basic examples of tasks you can accomplish using CSOM. objects available for creating client-side scripts using the SharePoint� Get started using the SharePoint client object model with external data. To develop solutions using the SharePoint client object model (CSOM), you will need the following: SharePoint. Visual Studio 2012. Office Developer Tools for Visual Studio 2012

I can confirm that SharepointOnlineCredentials works with external users from a different tenant. I could not get it to work for users not defined to an o365 tenant.

As stated by CodeMonkey, there is a newer set of csom libraries you will need to get using Nuget. Install Nuget package 'Microsoft.SharePointOnline.CSOM' - this will replace your references with newer versions of the CSOM libraries. Refer to:

Client Side Object Model (CSOM) | SharePoint Online, SharePoint Client Side Object Model (CSOM) allows developers to retrieve SharePoint developers have been using server side object model up until For C# developers Microsoft introduced . How to connect to SPO site. SharePoint Online is Software as a Service (SAAS) offering from Microsoft, available as part of Office 365. CSOM (Client Side Object Model) APIs are available for developers to connect to SharePoint Online sites. Using CSOM APIs, we can connect to SharePoint Online remotely and perform desired operations.

CSOM has dependency on UserProfile service, if SharePoint does not find user in user profile, it simply does not authenticate users.

thus external users are not part of user profiles that's why they can't be authenticated using CSOM.

SharePoint Client Object Modal (CSOM), Client Side Object Model (CSOM) was first introduced in SharePoint 2010. you will see how to perform list related tasks using the SharePoint 2013 . 365 / SharePoint Online - Connecting Office 365 / SharePoint Online� Hope this SharePoint tutorial explains, how to create a console application to connect to SharePoint Online site using visual studio and using the client-side object model (csom) code. Facebook Twitter LinkedIn Pinterest WhatsApp

Connect To SharePoint Online In Office 365 Using , In this article, we will see how to connect to SharePoint Online from NET managed CSOM (Client Side Object Model) modules. In order to work with SharePoint Client Object Model, we have to add two Internal Implementation walk through WriteLine("User Name:");; stringuserName = Console. Although SharePoint Online Management Shell provides a number of PowerShell Cmdlets to manage SharePoint Online, it is quite limiting and the only way to do real SharePoint PowerShell is using the SharePoint CSOM. The Client Side Object Model is a subset of the Server Object Model and can be used to supplement.

25+ SharePoint .Net Client Object Model Examples (CSOM , Net Client object model (CSOM); Retrieve SharePoint list items and display in Gridview Retrieve all users from SharePoint group using client object model code There are limitations to what can be done client-side compared to server- side, Working with JavaScript object model (jsom) in SharePoint 2013/2016/ Online� CSOM can be used to build custom apps on top of SharePoint online. In this blog, we are just going to focus on reading various high-level objects in SharePoint Online. SharePoint Client Side Object Model (CSOM) allows developers to retrieve, update and manage data in SharePoint Online. SharePoint Online makes the CSOM available in several forms.

SP 2010: Getting started with the Client Object Model in SharePoint , SharePoint 2010 Client Object Model – Creating your first client-side use the ClientContext object to connect and work with the SharePoint� Yet another powerful and old School approach is the use of the Console Application, which can harness the power of .NET managed CSOM (Client Side Object Model) modules. Open Visual Studio and create a console Application. In order to work with SharePoint Client Object Model, we have to add two references to the Console Application,

  • Do you use proxy to connect to the internet? That could be the reason too
  • @Matt - it could be. Is there a way I confirm? As I said I'm able to connect using a browser window.
  • Did you try with an external user? A user that's not in your Domain. I'm also able to connect using an internal user.