Forum Discussion
Connect to Excel file in SharePoint library using Service Principal
Hi sujaza,
- Thank you for the response. Now that you have added Sites.Read.All and Files.Read.All permissions to the Service Principal, in most cases these should generally be sufficient for accessing the SharePoint content.
- When you were using Sites.Selected before, microsoft requires to manually grant access to specific SharePoint sites. Which means explicitly telling SharePoint like allow this app (Service Principal) to read this site.
This can be done by using a Microsoft Graph API POST request:
Endpoint: POST https://graph.microsoft.com/v1.0/sites/{site-id}/permissions
Request body:
{
"roles": [ "read" ],
"grantedToIdentities": [
{
"application": {
"id": "client-id",
"displayName": "app-name"
}
}
]
}
Replace ‘site-id’ with your SharePoint Site ID, ‘client-id’ with your Azure App (Service Principal) Client ID and ‘app-name’ with the display name of your registered app. This will explicitly grants read access to the SharePoint site for the Service Principal.
If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!
Thanks and regards,
Anjan Kumar Chippa
I have since created a Microsoft support ticket and as per the MS Support team, authentication using Service principal is not supported for 'Sharepoint Folder Connector' as per the MS documentation below.
Power Query SharePoint folder connector - Power Query | Microsoft Learn
Interestingly, documentation on Web connector shows that this auth type is supported.
Power Query Web connector - Power Query | Microsoft Learn
However , I had no luck with both the connectors with Sharepoint.