I feel like I'm missing something here. I'm trying to login to a SPO tenant via a C# Console app, but I'm getting the error:
Cannot contact web site 'https://xxx.sharepoint.com/' or the web site does not support SharePoint Online credentials. The response status code is 'Unauthorized'.
I know the account works, as I'm able to login with the account directly from browsers. In the end, I'd like to use the CSOM to do CRUD operations on SP Lists, Term Stores and Document Libraries, but CSOM is not a hard requirement (and I admittedly don't know if REST APIs can do the whole job).
I've seen that changing the LegacyAuthProtocolsEnabled
value to True can help with this, but our security folks won't allow me to enable that feature.
The code is pretty vanilla:
SecureString passWord = getPassword();
using (var context = new ClientContext(URI))
{
context.Credentials = new SharePointOnlineCredentials(userName, passWord);//new NetworkCredential(userName, passWord);//
context.Load(context.Web, web => web.Title);
context.ExecuteQuery(); //Error happens here
Console.WriteLine("Your site title is: " + context.Web.Title);
}
As you can see, I've also tried passing the NetworkCredentials
object, which also doesn't work (I also get a 401 response).
As a further note, I've looked into App-only identities, but I don't believe I can use those due to their restrictions on managing taxonomy (ie. managed metadata within Term Stores) and managing files (though this may be a restriction only on using CSOM, it's not clear to me from this page)
Based on this, can you see what I'm doing wrong here? Or if there's a different/better way to do this, I'm open to that as well!
EDIT: Looks like when LegacyAuthProtocolsEnabled
is set to False I explicitly cannot use the SharePointOnlineCredentials
class at all, based on this page. Given that, looks like I need a different approach to get this access!