SharePoint ServerUnauthorizedAccessException: 'Attempted to perform an unauthorized operation.'

Amir tounsi 0 Reputation points
2024-04-22T06:29:44.5633333+00:00

i cannot load Web from SPO using Context.ExecuteQueryAsync, i receive alayws the same error Microsoft.SharePoint.Client.ServerUnauthorizedAccessException: 'Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))'

Property DisableCustomAppAuthentication is False

I used all type of connection like token.... and with ClientId+ClientSecret. I use this Application Permission in APP: Sites.FullControl.All

using (var clientContext = new PnP.Framework.AuthenticationManager().GetACSAppOnlyContext(siteUrl, clientId, clientSecret))

{

clientContext.Load(clientContext.Web, p => p.Title);

await clientContext.ExecuteQueryAsync();

Console.WriteLine(clientContext.Web.Title);

}

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,679 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ling Zhou_MSFT 13,260 Reputation points Microsoft Vendor
    2024-04-23T09:01:21.2133333+00:00

    Hi @Amir tounsi,

    Thank you for posting in this community.

    Based on the description of your problem, it seems that everything is fine with your configuration.

    We can check our operation again:

    1.Are you trying to grant access using SharePoint App-Only? If so, please refer to this article to make sure your configuration is OK.

    2.Please double check that your siteUrl, clientId, clientSecret are correct.

    3.Please double check that your Application Permission.

    4.Try another site.


    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.