using (Microsoft.SharePoint.Client.ClientContext ctx = authman .GetAppOnlyAuthenticatedContext(appUrl, clientId, clientSecret)) gives 401 error

developer sp1 461 Reputation points
2021-03-02T08:21:00.04+00:00

We are using Azure AD App Only authentication in CSOM for MFA users with Client Id/Secret.

The code like this:

var authman = new OfficeDevPnP.Core.AuthenticationManager();
using (Microsoft.SharePoint.Client.ClientContext ctx = authman .GetAppOnlyAuthenticatedContext(appUrl, clientId, clientSecret))
{
  Web web = ctx.Web;
  context.Load(web, w => w.Id, w => w.Title);
  context.ExecuteQueryRetry();
}

Code works fine in last year, however today, it's returning "The remote server returned an error: (401) Unauthorized."

Any solution for this ?

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,573 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amos Wu-MSFT 4,051 Reputation points
    2021-03-03T01:26:13.163+00:00

    Hi @developer sp1 ,
    We can only use certificates for realizing app-only access for the Azure AD app, all other options are blocked by SharePoint Online and will result in an Access Denied message.
    You could get this information here.


    If the response is helpful, please click "Accept Answer" and upvote it.
    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.

0 additional answers

Sort by: Most helpful