We need to provide automated access to our Sharepoint sites, so our customers can up/download files from their environment. We are building an internal self-service application for our customer teams that needs to do the following:
We would like to automate the admin consent part as we have hundreds of customers. I didn't find any reference to that. Also, if I call the https://graph.microsoft.com/v1.0/applications/{appid}
endpoint I don't see that there's any consent pending that would give me a clue where to search further.
How can we give consent with graph, without human interaction?
I created an Azure AD Application and added API permissions like below:
How can we give consent with graph, without human interaction?
Note that: One needs to have the Global Administrator, Privileged Role Administrator, or Application Administrator roles in order to grant Admin consent to the API permissions of the Azure AD Application.
Assign any one of the above roles to the Service principal.
Login with the Azure Service Principal and generate access token:
az login --service-principal -u "AppID" -p "ClientSecret" -t "TenantID"
az account get-access-token --resource https://graph.microsoft.com
To grant Admin consent to the Application type permission, check the below:
POST https://graph.microsoft.com/v1.0/servicePrincipals/SPObjID/appRoleAssignedTo
{
"principalId": "SPObjID",
"resourceId": "MicrosoftGraphResourceID",
"appRoleId": "APIpermissionID"
}
The Admin consent granted successfully to the API permission:
To get the values of resourceId
and appRoleId
of Sites.Selected permission run the below query:
https://graph.microsoft.com/v1.0/servicePrincipals?$filter=displayName eq 'Microsoft Graph'
To grant Admin consent to the Delegated API permission, check the below:
POST https://graph.microsoft.com/v1.0/oauth2PermissionGrants
{
"clientId": "ObjectIDofSP",
"consentType": "AllPrincipals",
"resourceId": "MicrosoftGraphResourceID",
"scope": "User.Read"
}
The Admin consent granted successfully to the API permission: