How to limit a service principal in AzureAD with graph API to only a certain site collection in SharePoint Online?

frob 4,261 Reputation points
2022-09-28T23:40:50.723+00:00

Hi there
How to limit a service principal in AzureAD with graph API to only a certain site collection in SharePoint Online?
Thanks.

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Tong Zhang_MSFT 9,251 Reputation points
    2022-09-29T06:19:48.347+00:00

    Hi @frob ,

    According to my research and testing, you can choose the permission ** Sites.Selected ** for your application instead of one of the other permissions, by default, result in your application not having access to any SharePoint site collections.

    245889-image.png

    Then administrators can grant permissions to an application, such as "Read", "Write", or "Read and Write" permissions. Along with Sites.Selected this will result in only those sites that have had permission granted being accessible.

    For example, if I wanted to grant the "My demo application" application write permission to a single site collection, you can use the following calls:

    POST https://graph.microsoft.com/v1.0/sites/{siteId}/permissions

    Content-Type: application/json

    Body:

    {  
        "roles": [  
            "write"  
        ],  
        "grantedToIdentities": [  
            {  
                "application": {  
                    "id": "Application (client) ID",  
                    "displayName": "My demo application"  
                }  
            }  
        ]  
    }  
    

    245830-01.png

    More information for reference: Controlling app access on a specific SharePoint site collections is now available in Microsoft Graph

    Hope it can help you. Thanks for your understanding.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.