In this blog, I will walk through the steps to create a new SharePoint site using an Azure Function App with custom Azure Active Directory (AD) authentication. This guide will cover the setup of the Azure Function App, the necessary configurations in Azure AD, and the deployment of the function to create SharePoint sites programmatically.
Prerequisites
- Azure subscription
- SharePoint Online tenant
- Azure AD with necessary permissions
Step 1. Create a New Azure Function App
- Create Function App: In the Azure portal, create a new Function App with the following settings.
* Runtime stack: PowerShell Core * Operating System: Windows - Add PnP.PowerShell Module: Modify the requirements.psd1 file to include the PnP.PowerShell module.
{ 'PnP.PowerShell' = '2.*' } - Disable MSI Authentication: In the profile.psd1 file, disable the Azure PowerShell MSI authentication section.
#if ($env:MSI_SECRET) { # Disable-AzContextAutosave -Scope Process | Out-Null # Connect-AzAccount -Identity #}
Step 2. Configure Authentication
- Add Identity Provider: In the Authentication blade of the Function App, add Microsoft as an identity provider. Note the name of the Azure AD application for later use.
- Enable Managed Identity: Enable the system-assigned managed identity for the Function App.
- Set Function Variables: Create the following application settings (variables).
- SPO_SENSITIVITY_LABEL: GUID of the sensitivity label to be applied to the SharePoint site.
- SPO_TENANT_NAME: Short tenant name (e.g.,
abcgroup).
Step 3. Create the Function
- Create HTTP Trigger Function: Create a new function with an HTTP trigger template named
NewSite. Set the authorization level to Anonymous (authentication will be handled via Azure AD integration). - Replace Function Code: Replace the default function code with the provided script to handle SharePoint site creation.
Step 4. Assign Permissions
Grant Permissions: Grant Directory.ReadWrite.All and Sites.FullControl.All permissions to the managed identity. Follow the steps in this guide to assign permissions.



Join the conversation! Your thoughts help the community grow.