An Azure service that provides an event-driven serverless compute platform.
Hello Fred Wong,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you are Implementing Delegated Graph API Access for an Azure Function Writing to SharePoint Site.
AI answer is mostly correct and @Mohammad Altaf technically yes. However, there is a missing point. The issue is Delegated Microsoft Graph permissions require a signed-in user context, whereas a Timer-triggered Azure Function is an unattended background process that authenticates using its own identity. Consequently, DefaultAzureCredential and Managed Identity can only obtain Application (app-only) access tokens and cannot authenticate using Delegated permissions.
The supported method for implementation is to:
- Grant the Function App's Managed Identity (or Service Principal) the Microsoft Graph Application permission
Sites.Selected. - Grant admin consent for the permission in Microsoft Entra ID.
- Have a SharePoint administrator assign the application's required access (
write,manage, orfullcontrol, as appropriate) only to the target SharePoint site. - Authenticate the Azure Function using
DefaultAzureCredentialand Microsoft Graph to upload the report.
If organizational policy prohibits Application permissions, there is no supported code change or Microsoft Graph authentication flow that enables Delegated permissions for a Timer-triggered Azure Function. In that case, the organization must either approve the documented Sites.Selected Application model or redesign the solution to use an interactive application where Delegated authentication is supported.
For more information, and implementation steps see:
- Microsoft Graph authentication concepts: https://learn.microsoft.com/graph/auth/auth-concepts
- OAuth 2.0 client credentials flow: https://learn.microsoft.com/entra/identity-platform/v2-oauth2-client-creds-grant-flow
- Azure Functions identity-based connections: https://learn.microsoft.com/azure/azure-functions/functions-identity-based-connections
- Microsoft Graph Selected permissions overview: https://learn.microsoft.com/graph/permissions-selected-overview
- Grant application access to a SharePoint site: https://learn.microsoft.com/graph/api/site-post-permissions
I hope this is helpful. Please! Do not hesitate to let me know if you have any other questions, steps or clarifications.
Please do not close the thread by upvoting and accepting the answer if any part of it is helpful.