you would use access tokens, rather than logging in. see thread:
CSOM backend with Modern Authentication
Hi,
I've been developing some backend code which connects to Sharepoint Online using CSOM (16.1) and .Net Framework (4.6.1)
_context = new ClientContext(_sharepointDocumentRootUrl);
SecureString securePassword = new SecureString();
foreach (char c in _sharepointPassword)
{
securePassword.AppendChar(c);
}
_context.Credentials = new SharePointOnlineCredentials(_sharepointUserName, securePassword);
This worked well until the auth method was changed in SharepointOnline from Legacy Auth to Modern Auth. Now we get a "The sign-in name or password does not match one in the Microsoft account system"
Of course, we've double/tripple-checked the username/password.
The system account has MFA turned off. The IT department wont let us use the SharePoint App-Only auth method. And they are very sceptical to allow legacy auth for or system account.
I've been googling around without any success. Any ideas?
2 answers
Sort by: Most helpful
-
-
RaytheonXie_MSFT 31,606 Reputation points Microsoft Vendor
2022-04-14T09:13:11.357+00:00 Hi @Thomas Hellström ,
Sharepoint Online credentials - is equivalent of having the users himself logging in with his password without him being present(by hardcoding the username and password). If Legacy Authentication method is blocked ( for security reasons ) - then an interaction from the user is required for going through the authentication and obtain the token for subsequent action.
Retrieving the token necessary to access the Sharepoint with interaction is not possible. So if you want to connect sharepoint with Modern Authentication. Sharepoint App Only is necessary.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.