CSOM backend with Modern Authentication

Thomas Hellström 11 Reputation points
2022-04-13T08:26:02.773+00:00

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?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,279 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,575 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,846 Reputation points
    2022-04-13T16:00:34.147+00:00
    0 comments No comments

  2. 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.