0

In our Azure functions, we have powershell scripts that connect to SharePoint online and give monthly reports. Recently, we discovered that connect-pnponline is fail to connect to SharePoint after upgrading to modern authentication in SharePoint. When we allow access apps in the below image without modern authentication, this will work fine.

Is there any way to overcome this issue in Azure functions? When SharePoint is upgraded to modern authentication, how can you connect it with Azure functions? I've tried different PnP commands but no luck

enter image description here

Here is the error :

[Error] Connect-PnPOnline : Cannot contact web site 'https://mytenant.sharepoint.com/' or the web site does not support SharePoint Online credentials. The response status code is 'Unauthorized'. The response headers are 'X-SharePointHealthScore=3, X-MSDAVEXT_Error=917656; Access+denied. The response status code is 'Unauthorized'. The response headers are 'X-SharePointHealthScore=1, X-MSDAVEXT_Error=917656;

1 Answer 1

1

Modern authentication uses OAuth 2.0, as you want to use SharePoint in azure function app which will run in background. You will require to register an daemon app with certificate in azure ad.

Refer this Microsoft docs for app registration with certificate.

After app registration you will require to upload the certificate in Azure Function App.

follow the below steps for uploading the certificate in function app.

  • Go to Setting -> TLS/SSL settings -> Upload certificate.
  • After this you can connect using PnP Power shell using below command.
  • Refer the below screen

upload certificate to function app

  • Use thumbprint to connect SharePoint online through PnP PowerShell in azure function.
  • Refer the below PnP PowerShell command.
Connect-PnPOnline -ClientId fa1a81f1-e729-44d8-bb71-0a0c339c0f62 -Url "https://tenant.sharepoint.com" -Tenant tenant.onmicrosoft.com -Thumbprint $thumbprint

Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.