0

I have a situation where I need to upload/download files using Sharepoint from Azure function app. I have read documentation and I see that App-Only way is preferred. Can someone tell me what would be the best way to authenticate to Sharepoint online site using Azure function app and CSOM as a library.

Thank you in advance.

Expect to find optimal solution for authenticating.

  • 1
    Are you sure, you need that _old way_ to accomplish your task? The graph SDK can access [lists, sites and driveItems](https://learn.microsoft.com/en-us/graph/api/resources/sharepoint?view=graph-rest-1.0) within SharePoint. There is also an [example](https://github.com/microsoftgraph/msgraph-sample-azurefunction-csharp) on how to access Graph from an Azure Function. – Oliver Mar 28 '23 at 09:11
  • I agree with @Oliver - MicrosoftGraph should be the way to go. – Ivan Gechev Mar 28 '23 at 09:22
  • When you say the old way. Are you referring to AppOnly approach or using CSOM and not Sharepoint api? @Oliver – Marko Rakic Mar 28 '23 at 09:26
  • If I change the approach to use Microsoft Graph could I use OAuth2.0 Client Credentials flow and authenticate to Microsoft Graph in that way. Then I would create and configure App registration to access specific Sharepoint site and give right permissions. From Azure function app I would generate a token using classic Microsoft endpoint and then use that token for working with sharepoint. – Marko Rakic Mar 28 '23 at 09:51
  • I find that using LogicApps is a nice way to do it and it’s extremely light. Not for everyone but don’t discount it. Makes it very easy. I’m not talking about replacing your function either, I’m talking about creating an API type approach just to upload the file. – Skin Mar 28 '23 at 10:04
  • Thanks for the idea @Skin. Problem is that I need to use Function app because it depends on a lot of other stuff. – Marko Rakic Mar 28 '23 at 10:06
  • By saying _the old way_ I mean nearly every API that Microsoft provided next to the graph api. MS tries to move all existing ones under this endpoint (or similar with other base url, but same auth mechanism). Some are still not available, in beta or support only a subset of functionality, but it seems that MS is going that way for all APIs. IMHO this is great cause retrieving auth tokens for this interface is well documented and a lot of different flows (interactive, device, behalf-of, B2B) are available depending on your use case. – Oliver Mar 29 '23 at 06:35

1 Answers1

0

You can opt for Microsoft Graph, it has a wide variety of authentications options and you can access almost anything in Microsoft 365.

Ivan Gechev
  • 706
  • 3
  • 9
  • 21