question

developersp1-9584 avatar image
0 Votes"
developersp1-9584 asked ·

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

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 ?

office-sharepoint-server-development
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AmosWu-MSFT avatar image
1 Vote"
AmosWu-MSFT answered ·

Hi @developersp1-9584 ,
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 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @developersp1-9584
Do you have any update on this issue?

0 Votes 0 ·