I am trying to update an internal application that updates a SharePoint list to be able to authenticate using the users current credentials to Office 365 SharePoint. I keep getting a error "The remote server returned an error: (401) Unauthorized." Does Office 365 SharePoint not support CredentialCache?
Here is a simple example that I am trying.
static void Main(string[] args)
{
ConsoleColor defaultForeground = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Green;
//Office 365 Site URL
string webUrl = "https://sp_site.sharepoint.com/";
using (var newlistitem = new ClientContext(webUrl))
{
//newlistitem.Credentials = new SharePointOnlineCredentials(userName, password); works
newlistitem.AuthenticationMode = ClientAuthenticationMode.Default;
newlistitem.Credentials = CredentialCache.DefaultNetworkCredentials;
//Also tried just DefaultCredentials - same error
List spList = newlistitem.Web.Lists.GetByTitle("List1");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem newItem = spList.AddItem(itemCreateInfo);
newlistitem.Load(spList);
newItem["Title"] = "Test1";
newItem.Update();
newlistitem.ExecuteQuery();
}
}