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/&#8217; 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.

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.