Sharepoint AzureAD app access with specific sites

Background

When giving app access to sharepoint in AzureAD it by default gives it to all sites, this is in most cases not prefered as you could have sensitive sites that you do not want the integrated app to have access to. In my case, I wanted to pass some specific sites to Gemini's RAG engine.

About

The sites.selected permission will help fix this, it allows you to set permissions per sharepoint site.

How to Control App Access to a Specific SharePoint Site Collection

🔐 1. Assign Sites.Selected permission

⚙️ 2. Grant site-specific access via Graph API

As a SharePoint admin, use the Microsoft Graph endpoint:

Tip! Use graph explorer
POST https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/demo:/permissions
Content-Type: application/json

{
  "roles": ["write"],
  "grantedToIdentities": [
    {
      "application": {
        "id": "89ea5c94-7736-4e25-95ad-3fa95f62b66e",
        "displayName": "Foo App"
      }
    }
  ]
}

📘 3. Use permissions in your application


✅ 4. (Optional) Update permissions