'How to get list of accessible sites with Sites.Selected

How can I enumerate sites that my application has been granted access to (via Microsoft Graph's site permission endpoint)?

The sites are to be used in queries later on in context with the Sites.Selected app permission.

The known method, https://graph.microsoft.com/v1.0/sites?search=*, doesn't work with the Sites.Selected permission.

Edit: According to Jeremy Kelley in this demo https://youtu.be/wcJRQDsXMQ8?t=717 there is currently no way of listing the sites. I'll leave the question open for alternative/future solutions.



Solution 1:[1]

• Sorry, you can’t get the list of Sharepoint sites an application has access to through the Microsoft Graph API. Instead, you can surely get the list of applications a Sharepoint site has access to. Thus, through Microsoft Graph Rest API HTTP query, you can get the list of permissions a sharepoint site has as follows: -

Graph query: -

GET https://graph.microsoft.com/v1.0/sites/{sitesId}/permissions/{permissionId}

Output: -

HTTP/1.1 200 OK Content-Type: application/json

{ "id": "1", "@deprecated.GrantedToIdentities": "GrantedToIdentities has been deprecated. Refer to GrantedToIdentitiesV2", "roles": ["read"], "grantedToIdentities": [{ "application": { "id": "89ea5c94-7736-4e25-95ad-3fa95f62b66e", "displayName": "Contoso Time Manager App" } }], "grantedToIdentitiesV2": [{ "application": { "id": "89ea5c94-7736-4e25-95ad-3fa95f62b66e", "displayName": "Contoso Time Manager App" } }] } ’

Thus, in this way, you can the list of applications a Sharepoint site has permissions to and thus you can make a list of it vice versa.

For more details, please find the documentation link below: -

https://docs.microsoft.com/en-us/graph/api/site-get-permission?view=graph-rest-1.0&tabs=http

Also, please refer to the below SO thread link for more details on getting the list of permissions an application has: -

Using Microsoft.Graph to get current application permissions

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 KartikBhiwapurkar-MT