1I am using the "Sites.Selected" delegated permission scope to read files from SharePoint on behalf of the logged-in user. I have granted delegated read permission on a specific site to my Azure AD application, and I have also added the "Sites.Selected" permission to my Azure AD application. In theory, my application should be able to download documents for the signed-in user.
To generate a token, I am using the "Sites.Selected" scope, which I will then send to the Graph API to download the user's documents. However, when I attempt to log in, the Microsoft login page displays an error message stating that I need admin approval.
Could anyone please explain why I am encountering this "Need admin approval" error message when trying to log in to my application, despite having the necessary permissions?
Sample Code: https://github.com/Azure-Samples/active-directory-dotnet-desktop-msgraph-v2
Scope : Sites.Selected
I created a Microsoft Entra ID application and added API permissions same as you:
When I tried to download the file, I got the same error as you:
The error usually occurs if the admin consent is not granted to the API permissions which requires consent.
Hence to resolve the error, either grant admin consent to the API permissions added to the application OR set User consent settings as "Allow user consent for apps" like below:
Go to Enterprise applications -> Consent and permissions -> User consent settings
You can also select the "Allow user consent for apps from verified publishers, for selected permissions (Recommended)" option and set the required permissions.
Now the user can consent for applications:
Now the user can consent for apps and call the API.
The Sites.Selected
API permission will allow access to only the selected sites which is set up like briefed in this blog by Patrick Rodgers.
For sample, I tried to download the signed in user file by passing the item id.
For this to work, I added Files.ReadWrite
delegated API permission:
string graphAPIEndpoint = "https://graph.microsoft.com/v1.0/me/drive/items/ItemID";
string[] scopes = new string[] { "Files.ReadWrite" };
Based on the API you are calling you need to add permission to the Microsoft Entra ID application.
Reference: