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);
            newItem["Title"] = "Test1";



1 Answer 1


For Local, by default the managed client object models authenticate users by using their Windows credentials (DefaultCredentials).So you don't need to explicitly set the Credentials for local.

But for Office 365, you have to pass the credentials:

context = new ClientContext(siteURL);
SecureString spassWord = new SecureString();
foreach (char c in password.ToCharArray()) spassWord.AppendChar(c);

context.Credentials = new SharePointOnlineCredentials(userName, spassWord);
web = context.Web;

  • You are correct. I tried every different combination that I could think of, but I could not get it to pass the local credentials. I thought that this would work, but it did not.
    – stivy
    Oct 14, 2016 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.