Skip to content
Skip to content
Menu
A cup of dev
  • Home
  • About
  • Contact
  • Books and ink
A cup of dev

Give your app granular permissions to a specific site or list in SharePoint

By Eli H. Schei on Wednesday, 18 December 2024, 9:35Wednesday, 18 December 2024, 9:35

When building SharePoint apps, one of the key considerations is ensuring your app has the right level of access to perform its tasks—no more, no less. Over-permissioning can lead to security risks, while under-permissioning can hinder functionality. Fortunately, SharePoint offers granular permission settings like Site.Selected and Lists.SelectedOperations.Selected, allowing developers to scope permissions to a specific site or list in SharePoint. In this post, I’ll explain how to configure these permissions effectively.

Prerequisites:You need a app-registration in Entra ID that has the Site.Selected or Lists.SelectedOperations.Selected set.

If you don’t know how to create an app registration this blogpost covers how to do so. After creation go to API permissions, select Graph – application permissions – and Site.Selected or Lists.SelectedOperations.Selected

Get site ID

First you need to get the full site-id, this is combination of your sharepoint domain, web-id, and site-id. The quickest way to get it is to use Graph Explorer and do a GET request to the following endpoint:

https://graph.microsoft.com/v1.0/sites/{YOUR_DOMAIN}.sharepoint.com:/sites/{NAME_OF_SITE}/

This will give you back a respons like this, you should copy the whole id listed in id. {your_domain}.sharepoint.com,{some-guid},{some-other-guid}

{
   #.... (shortend for readability)

    "description": "DMO-site",
    "id": "YOURDOMAIN.sharepoint.com,26192b3a-c1b9-4849-9f80-bfc66c12345a,159b904f-9880-481e-ac3f-12345da331f9",
    "lastModifiedDateTime": "2024-12-17T11:35:08Z",
    "name": "DMO-site",
    "webUrl": "https://YOURDOMAIN.sharepoint.com/sites/DMO-site",
   # .... 
}

When you have the site ID you are ready to set the permissions you want.

Give granular permissions to a site (Site.selected)

Note, to be allowed to set these permissions you need to be logged in with a user (or app) that has admin privileges, its not enough to just be an owner of the SharePoint Site. If using Graph Explorer open the permission tab and give it Sites.FullControl.All.

Another way to grant permissions to your site collection is by using PnP PowerShell, which provides a straightforward approach for managing permissions. However, I typically prefer using Microsoft Graph for this task so thats what I’ll cover in this blogpost.

Using the ID you got in the previous step make a POST request to the graph endpoint:

https://graph.microsoft.com/v1.0/sites/{site-id}/permissions

With this json in the body of your request:

{
    "roles": [
        "write"
    ],
    "grantedToIdentities": [
        {
            "application": {
                "id": "YOUR_APP_REG_ID",
                "displayName": "YOUR_APP_REG_NAME"
            }
        }
    ]
}

And thats it, your app-registration now have writing permissions to your selected site.

Give permissions to list (List.SelectedOperations.Selected)

Granting your app granular permissions at the list level is a relatively new capability in SharePoint development so you’ll need to use Microsoft Graph’s beta endpoint to configure it. Below is an example of how to make POST request.

https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/permissions

Note that the body of this request is slightly different to the one used on a site leve.

{
  "roles": ["write"],
  "grantedTo": {
    "application": {
      "id": "YOUR_APP_REG_ID"
    }
  }
}

Summary

Setting up the right permissions for your SharePoint app is key to keeping things secure and working smoothly. In this post, we covered how to give your app more specific permissions, like limiting access to a single site with Site.Selected or a specific list with List.SelectedOperations.Selected. We also covered how to use Microsoft Graph’s beta endpoint to set these permissions.

Resources

  • Develop applications that use Site.Selected permissions for SPO sites (blogpost from MS tech community)
  • PnP-powershell Grant-PnPAzureADAppSitePermission
  • Selected permissions in OneDrive and SharePoint (Micosoft docs)

If you are interested in Microsoft 365 Development you might also like my other blogposts in this category.

Also, if you have any feedback or questions, please let me know in the comments below. 🙂

Thank you for reading, and happy coding!

/Eli

If you want to support my content you can

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X

Post navigation

Microsoft Graph Magic: Simplifying User Removal from teams in Microsoft Teams
How to use Azure CLI to deploy Azure Functions: Step-by-Step Guide

Leave a ReplyCancel reply

Eli H. Schei

I'm a front-end developer who mainly work in the Microsoft 365-sphere. As a developer I read a lot of blogs. And in my experience I can read multiple different blogposts about exactly the same topic, and only one of them makes sense to me. Therefore I’m adding my voice to the mix, and hopefully one of my blogposts will be the one that makes sense of a topic for you. You can learn more about me here.

Recent Posts

  • React in ListViewCommandSet – how to fix the “Cannot read properties of undefined (reading ‘id’)” error
  • How to Get Site-ID with Graph Explorer (and other SharePoint info)
  • How to use Azure CLI to deploy Azure Functions: Step-by-Step Guide
  • Give your app granular permissions to a specific site or list in SharePoint
  • Microsoft Graph Magic: Simplifying User Removal from teams in Microsoft Teams

Categories

  • Azure
    • Azure CLI
    • Azure functions
  • Level
    • Beginner
    • Intermediate
  • Microsoft 365 Development
    • Microsoft Authentication Library
    • Microsoft Graph
    • Microsoft Teams
    • PNP powershell
    • PowerApps
      • PowerApps Component Framework
    • SharePoint Framework
    • SharePoint Online
  • Tech Lead
  • Web development
    • Accessibility
    • Soft skills
    • Tips and tricks

Tags

accessibility app permissions ARIA azure Azure CLI azure functions Content creation custom themes favorites git github ListViewCommandSet M365 CLI M365 development MS Graph PCF PnPjs PnP powershell power apps PowerApps Component Framework quicktip react resources SharePoint Online Sideloading SPfx Teams teams app dev Teams apps Tech lead tools wcag webdev Windows terminal
©2025 A cup of dev | WordPress Theme by SuperbThemes.com