Unable to authenticate through sharepoint using M365 account or AppID&Appsecret by C# code.

Hachi Liu 刘帅 0 Reputation points
2023-04-17T05:19:12.1366667+00:00

I'm trying to performing CRUD operations to the list in sharepoint using C # code, but I have encountered two issues and cannot find a valid reference document online. Can someone give me some suggestions or reference links? Thank you in advance. 1>.Microsoft.SharePoint.Client.IdcrlException: The sign-in name or password does not match one in the Microsoft account system. User's image

in this case,it seems that this error was caused by us turning on MFA authentication, but after I asked the AZURE administrator to turn off MFA authentication for my account, I still encounter this error.

2>.Microsoft.SharePoint.Client.ServerUnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
in this case,i'm the creater of the target sharepoint,why my access was denied?do I need to make any settings for my site or ask administrator make any change for our sharepoint policies? User's image

Microsoft 365 and Office SharePoint Server For business
Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
Developer technologies C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-04-17T08:17:39.3466667+00:00

    Hi @Hachi Liu 刘帅

    For user name and password login, please clear the cache of the browser and log in the site with the account to check the password and MFA is disabled. If MFA is disabled, you could try to change the password of the user.

    For the client id and secret login, you are used a tenant scope app create the site. If you want to access the site, you will need to register a new app which is sitecollection scope.

    Please refer to the following document

    https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/add-in-permissions-in-sharepoint#types-of-add-in-permissions-and-permission-scopes

    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.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.