CSOM error Exception calling “ExecuteQuery”

If you are trying to run CSOM against SharePoint Online and gets the error below

Exception calling “ExecuteQuery” with “0” argument(s): “Cannot contact web site ‘https://tenant.sharepoint.com/’ or the web site does not support SharePoint Online credentials. The response status code is ‘Unauthorized’.

The cause of this issue:  LegacyAuthProtocolsEnabled

By default this property should be set to $True, but sometimes it might be set to $False,

Change this back to $True and the authentication error should go away.

https://technet.microsoft.com/en-us/library/fp161390.aspx

LegacyAuthProtocolsEnabled Optional System.Boolean By default this value is set to $True.

Setting this parameter prevents Office clients using non-modern authentication protocols from accessing SharePoint Online resources .

A value of True– Enables Office clients using non-modern authentication protocols (such as, Forms-Based Authentication (FBA) or Identity Client Runtime Library (IDCRL)) to access SharePoint resources.

A value of False-Prevents Office clients using non-modern authentication protocols from accessing SharePoint Online resources .

NoteNote:
This may also prevent third-party apps from accessing SharePoint Online resources.
Also, this will also block apps using the SharePointOnlineCredentials class to access SharePoint Online resources. For additional information about SharePointOnlineCredentials, see SharePointOnlineCredentials class.

CSOM error in tenant:
LegacyAuthProtocolsEnabled                 : False

csomerror01

CSOM worked in tenant:
LegacyAuthProtocolsEnabled                 : True

csomerror02

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s