Configure SharePoint authentication and site access
Which SharePoint Connection Should I Use?
When creating a SharePoint connection in StackAI, there are 3 available methods: through OAuth connection, an App-only (client credentials) connection, or an NTLM connection.
OAuth Connection (Delegated Access): An OAuth connection uses Microsoft’s OAuth 2.0 flow to authenticate on behalf of a user. StackAI accesses SharePoint using the permissions of the signed-in user.
App-Only Connection: An App-Only connection uses an Azure App Registration with application permissions. So StackAI authenticates as an application, not a user.
NTLM Connection: This is a legacy Microsoft authentication protocol commonly used in on-prem SharePoint or environments that do not support OAuth.
We recommend using a SharePoint OAuth2 or App-Only Connection:
Use OAuth if you want access scoped to individual users.
Use App-only if you want centralized control over permissions, or want access scoped to enterprise service accounts.
Set up App-Only Connection
Create an application for the StackAI connection with Microsoft Graph Sites.Selected application permission. Grant this application access to each required site.
Choose how your administrator will grant site access before you create additional applications:
PnP PowerShell: use your tenant's PnP app registration and an authorized administrator account. This route does not need the Admin App described in Step 1.
Microsoft Graph API: use a separate Admin App with the permission needed to grant site access. Keep its credentials with your IT team; do not enter them in the StackAI connection.
Skip Step 1 if you use PnP PowerShell or already have the administrative application. Both routes use the StackAI SharePoint App created in Step 2.
Step 1: Set up an Admin App (Optional)
Go to App Registrations on Microsoft Azure (link)
Create a new app registration
Add a name to the app
Select “Accounts in this organizational directory only (
your org nameonly - Single tenant)Register

Set up the app API permissions:
Under Manage go to API permissions

Click on “Add a permission”

Select Microsoft Graph

Select “Application permissions”

Add Sites.FullControl.All permission

Grant admin consent to the app

Step 2: Register a SharePoint app in Azure Active Directory (Microsoft Entra)
Sign into the Azure Portal with admin credentials.
Navigate to Azure Active Directory > App registrations.
Click New registration.
Enter your application name
Select “Accounts in this organizational directory only (
your org nameonly - Single tenant)Leave the redirect URI unset for this app-only client-credentials connection. The OAuth connector has a separate redirect-URI setup below.
Click Register.
Step 3: Configure Permission Scope
Navigate to API permissions > Add a permission > Microsoft Graph

Select Application permissions and add
Sites.Selected. Step 5 grants read or write access to each required site.

Grant admin consent

If admin consent is not granted, the connection may appear as Unhealthy in StackAI.
Step 4: Create Client Secret
Under your app registration, go to Certificates & secrets > New client secret

Configure SharePoint authentication and site access setup Add a description and select an expiry period.
Copy the generated secret value (not secret ID) immediately and store it securely. This is your
sharepoint_client_secret. You won't be able to view it again after leaving the page.
Configure SharePoint authentication and site access setup
Step 5. Grant SharePoint Site Access to the SharePoint App
Each SharePoint site has a unique set of Microsoft Graph IDs. We will use these identifiers to grant permission to the specific sites.
For a sample site https://<your organization domain>.sharepoint.com/sites/<site name>, there are three components to construct the full ID.
Host Name: This is in the site URL. Example:
<your organization domain>.sharepoint.comSite Collection ID:
Add
_api/site/idto the end of the site URL. Example:<your organization domain>.sharepoint.com/sites/<site name>/_api/site/idPress Return key to run this url, and you will see an XML file. The
Guidfield is the Site Collection ID.
Site Web ID:
Add
_api/web/idto the end of the site URL. Example:<your organization domain>.sharepoint.com/sites/<site name>/_api/web/idPress Return key to run this url, and you will see an XML file. The
Guidfield is the Site Web ID.
Construct the full ID: Append all three identifiers together in the order of
Host Name,Site Collection ID,Site Web IDseparated by comma. Example:<your organization domain>.sharepoint.com,12345678-90ab-cdef-1234-567890abcdef,abcdef12-3456-7890-abcd-ef1234567890
Once you have the site ID, grant the StackAI SharePoint App access to that site. There are two ways to do this, and they have the same end result:
Option A: PnP PowerShell (recommended). One command per site, and no access token to obtain or copy between commands. Does not require the Admin App from Step 1.
Option B: Microsoft Graph API. Use this if you cannot install PowerShell modules in your environment. Requires the Admin App from Step 1.
Whichever option you choose, repeat it for each site you would like to add to the SharePoint app.
Option A: Grant access with PnP PowerShell (recommended)
PnP PowerShell is Microsoft's community-maintained module for SharePoint administration. It calls the same Microsoft Graph endpoint as Option B, but it handles authentication for you, so there is no access token to obtain, copy, or refresh before it expires.
Requirements
PowerShell 7.4 or later. Windows PowerShell 5.1 is not supported.
An account with the delegated
Sites.FullControl.AllMicrosoft Graph permission. Note this is a delegated permission granted to the account you sign in with, which is different from the application permission described in Step 1.An app registration for PnP PowerShell itself. As of September 9, 2024 PnP PowerShell no longer ships with a shared multi-tenant app, so each tenant registers its own once. If your organization already uses PnP PowerShell, this already exists and you can skip that command below.
A few notes on the parameters:
-AppIdis the Client ID of the StackAI SharePoint App from Step 2, not the Admin App.-Permissions Readis the equivalent of"roles": ["read"]in Option B. UseWriteinstead if your workflows create or update files.-Siteaccepts the site URL directly, so you do not need the composite site ID for this command. You still need it for Step 6.On older versions of the module these cmdlets are named
Grant-PnPAzureADAppSitePermissionandGet-PnPAzureADAppSitePermission. Both names refer to the same commands.
Option B: Grant access with the Microsoft Graph API
To grant permission to the specific sites, you will first need the access token from the Admin App. Note, this is different from the Client Secret.
You can find the Tenant ID, Admin App Client ID from the Azure Portal > Overview.

You can find the Client Secret from the Azure Portal > Manage > Certification & Secrets.

Below is the command to obtain the access token from the Admin App.
With the access token, run the following command to grant read permission to the site. Run the command for each site you would like to add to the SharePoint app.
Use the full site ID constructed in the previous step.
Target App Client ID is the Client ID of the SharePoint app.
The curl commands above are written for bash. In Windows PowerShell, curl is an alias for Invoke-WebRequest and does not accept these flags, so run them from WSL, Git Bash, or Azure Cloud Shell, or use Option A instead.
Step 6: Setting Up App-Only Connection in StackAI

The connection requires several key pieces of information:
1. Client ID (string, required)
What it is: A unique identifier for your Azure AD application (also called "Application (client) ID").
Where to find it: In the Azure portal, under "Azure Active Directory" > Under "Manage" select "App registrations" > [Your App] > "Overview".
2. Client Secret (string, required)
What it is: A password-like value generated for your Azure AD application, used to authenticate your app.
Where to find it: In the Azure portal, under "Azure Active Directory" > "App registrations" > [Your App] > "Certificates & secrets". You must create a new client secret and copy the value. Make sure you copy the Client Secret Value, not the Secret ID.
3. Tenant ID (string, required)
What it is: The unique identifier for your Microsoft 365 tenant (organization).
Where to find it: In the Azure portal, under "Azure Active Directory" > "Overview" > "Tenant ID".
4. SharePoint Site ID (string, optional if the Entra App permission is Sites.Read.All and required if the permission is Sites.Selected)
What it is: The unique identifier for the SharePoint site you want to access. This is not the site URL, but an internal ID.
Where to find it: See Step 5 above on how to obtain the Site ID.
Set up OAuth2 Connection
For the built-in OAuth connector, sign in from StackAI and have your administrator approve the requested permissions if your tenant requires approval. Complete the steps below only when configuring your own Microsoft Entra application and custom OAuth connector.
Step 1: Register a New App in Microsoft Entra ID
Sign in to the Microsoft Entra admin center (or Azure Portal).
Navigate to Identity > Applications > App registrations.
Click New registration.
Fill in the form:
Name: A descriptive name such as
StackAI SharePoint OAuth2 Connector.Supported account types: Single tenant
Redirect URI: copy the redirect URI shown in your StackAI connector configuration
Click Register.
On the app's Overview page, copy and save:
Application (client) ID: this becomes the Client ID in StackAI.
Directory (tenant) ID: this becomes the Tenant ID in StackAI.
Step 2: Add Microsoft Graph API Permissions
The connector requests the following delegated Microsoft Graph permissions by default:
User.Read
Delegated
Read the signed-in user's profile (used for health checks via /me)
Sites.Read.All
Delegated
Read all SharePoint sites the user can access
Sites.ReadWrite.All
Delegated
Read and write all SharePoint sites the user can access
offline_access
Delegated
Obtain refresh tokens so sessions persist without re-login
openid
Delegated
OpenID Connect sign-in
profile
Delegated
Read basic profile information
email
Delegated
Read the user's email address
Least-privilege alternative: If you would like to use actions such as search files (i.e. search across files in SharePoint sites based on user question),
Sites.Read.Allis required for delegated access.Sites.Selectedis not currently supported for the Microsoft search file endpoint.
Independent of site permissions, keep User.Read for the connection health check, which calls Microsoft Graph /me. Keep offline_access so authorization can return a refresh token. These permissions do not grant access to SharePoint files. See Microsoft identity scopes.
To confirm the minimal scopes for the intended use case, you can check https://www.stackai.com/settings/connectors/sharepoint

To add these permissions in Azure:
In the app registration, go to API permissions > Add a permission.
Select Microsoft Graph.
Select Delegated permissions.
Search for and select each permission listed above:
User.Read,Sites.Read.All,Sites.ReadWrite.All,offline_access,openid,profile,email.Click Add permissions.
Step 3: Grant Admin Consent
Sites.Read.All and Sites.ReadWrite.All are high-privilege permissions that require an administrator to pre-authorize them on behalf of the entire organization. Without this step, individual users will be prompted to consent (or blocked, if your tenant disables user consent).
In the app registration, go to API permissions.
Click Grant admin consent for <your tenant name>.
Confirm the dialog that appears.
You should see all permissions show a green checkmark under the Status column with the label "Granted for <tenant>".
Required role: At minimum Cloud Application Administrator. For SharePoint site-level permissions managed via the SharePoint admin center, Global Administrator may be required.
Step 4: Create a Client Secret
In the app registration, go to Certificates & secrets > Client secrets.
Click New client secret.
Enter a Description (e.g.,
StackAI SharePoint Connector secret) and choose an Expires duration.Click Add.
Copy the secret Value immediately (it is only displayed once). This becomes the Client Secret in StackAI.
Once you have obtained the secret, you can complete the setup in StackAI UI at https://www.stackai.com/settings/connectors/sharepoint.
Connection fields and action reference
See Microsoft SharePoint for the current connector fields and supported actions.
Was this helpful?

