Connect to SharePoint online from Azure Function and ASP.NET core web application using REST API

john john 1,021 Reputation points
2022-12-08T00:14:41.343+00:00

We are developing those 2 components inside our project:-

1) Azure Function which run on daily basis and which read/write to SharePoint Online lists and libraries.

2) ASP.NET core web application which integrate with SharePoint using REST API.

now we are stuck on the following 2 points:-

Question-1) how we can authenticate those 2 components?

Question-2) In the Azure Function we want to pass the credentials of an admin account, while for the ASP.NET core web application we want to pass the login user credentials when connecting to SharePoint (so if the user tried to create a new SP item from ASP.NET core application, then the user should have the needed permission on the SP list) .

now we found those links which uses 2 different approaches for authentication (one using AZURE AD APP while the other uses username and password)

https://sharepointstew.wordpress.com/2021/07/07/app-only-authentication-in-sharepoint-online-using-latest-azure-sdk/

https://www.c-sharpcorner.com/article/authenticate-sharepoint-using-pnp-framework-in-an-azure-functions/

so what are the differences between those 2 approaches? and which one best suites our needs as per the above 2 questions?

Thanks

Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-12-08T05:47:54.7+00:00

    Hi @john john
    When you have applications, hosted services, or automated tools that need to access or modify resources, you can create an identity for the app. This identity is known as a service principal. Access to resources is restricted by the roles assigned to the service principal, giving you control over which resources can be accessed and at which level. For security reasons, it's always recommended to use service principals with automated tools rather than allowing them to log in with a user identity.
    So I will recomend you to use Azure AD app only to approach for authentication. For more details, Please refer to the document
    https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly


    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.


    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.