Grant Microsoft Graph Permissions to the App Service Managed Identity
The App Service authenticates to Microsoft Graph using its system-assigned managed identity. The Azure portal has no UI for assigning Microsoft Graph application permissions to a managed identity, so this step is a PowerShell script you run once after deployment. After it completes, the App Service can call Graph as itself, with no client secret and no stored credential.
Before You Begin
Section titled “Before You Begin”To run the script, you need:
- An account that can grant application permissions in Microsoft Entra ID, such as Privileged Role Administrator or Global Administrator.
- Website Contributor or higher on the App Service.
The script also needs three values from the deployment:
- In the Azure portal, go to your resource group > Deployments.
- Select the deployment that just completed, then select Outputs.
- Copy appName (the App Service name) and appServicePrincipalId (the managed identity’s principal ID).
- Note the resource group you deployed into.
You can also find the principal ID later under App Service > Identity > System assigned > Object (principal) ID. appName is the App Service resource name.
Download the Script
Section titled “Download the Script”Download Grant-AppStoreGraphPermissions.ps1. It’s plain text, so you can read it before you run it.
To check that the download is complete and unchanged, compare its SHA-256 hash with this value:
51C1084CCF94F8925039DF5F36131CAB11E0CFC41E46E70D1B522F3623882821(Get-FileHash ./Grant-AppStoreGraphPermissions.ps1 -Algorithm SHA256).HashRun the Script
Section titled “Run the Script”The easiest place to run the script is Azure Cloud Shell, which has the required modules and is already signed in to Azure.
-
Open Azure Cloud Shell in PowerShell, signed in to the tenant App Store for Intune is deployed in.
-
Download the script:
Terminal window Invoke-WebRequest https://powerstacks.com/docs/app-store-for-intune/downloads/Grant-AppStoreGraphPermissions.ps1 -OutFile Grant-AppStoreGraphPermissions.ps1 -
Run it with your three values:
Terminal window ./Grant-AppStoreGraphPermissions.ps1 -ResourceGroupName "<resource group>" -AppServiceName "<appName>" -AppServicePrincipalId "<appServicePrincipalId>" -
Sign in to Microsoft Graph with your administrator account when asked. In Cloud Shell, the sign-in uses a code: open
https://login.microsoft.com/devicein another browser tab, enter the code, and sign in. If the sign-in times out, the script stops without changing anything, and you can run it again.
To run the script on your own computer instead, sign in to Azure with Connect-AzAccount first, then run the same command. The script installs any module it needs that you don’t already have, for the current user. If PowerShell reports that the script isn’t digitally signed, review it, run Unblock-File ./Grant-AppStoreGraphPermissions.ps1, and then run it again. In a remote session without a browser, add -UseDeviceCode.
If your account can access more than one tenant, add -TenantId "<tenant ID>". The script signs in to Azure and Microsoft Graph in the same tenant, and stops without changing anything if they don’t match.
To see what the script would grant without changing anything, add -WhatIf.
By default the script grants the eight required permissions and Mail.Send. It grants the device check-in permission only if you ask for it. See Optional Permissions.
What the Script Does
Section titled “What the Script Does”- Checks that the App Service has a system-assigned managed identity, and that the identity, and the appServicePrincipalId you supplied, belong to that App Service.
- Grants the eight required permissions to that identity, plus
Mail.Sendunless you leave it off, and the device check-in permission only if you ask for it. A permission that’s already granted is reported as Already granted and left as it is. - Reads the identity’s permissions back from Microsoft Entra ID, so it reports success only for permissions that are actually in place.
- If it granted anything, waits about 2 minutes for the permissions to propagate, stops the App Service, waits 30 seconds, and starts it again.
The grant itself takes about 10 seconds, so allow 4 to 5 minutes in total. The portal is unavailable while the App Service is stopped.
The script stops and starts the App Service instead of restarting it. Azure caches the managed identity’s Microsoft Graph token outside the App Service: a restart doesn’t refresh that token, and a stop and start does.
The script reports each permission as Granted or Already granted, and its last line starts with Done. For each optional permission it didn’t grant, it says what won’t work. If a permission can’t be granted, or you decline one when you run the script with -Confirm, the script lists it, doesn’t stop the App Service, and exits with code 1. Fix the cause and run the script again. Permissions it already granted are kept.
If Reports > Store Health shows Microsoft Graph permissions as Unhealthy afterward, stop the App Service and start it once more. If Graph calls still fail, for example Sync Apps from Intune fails, see Graph calls fail after a restart.
Required Permissions
Section titled “Required Permissions”App Store needs all eight. Without any one of them, Reports > Store Health shows Microsoft Graph permissions as Unhealthy, and part of App Store stops working.
| Permission | Used for | What doesn’t work without it |
|---|---|---|
DeviceManagementApps.Read.All | Read the existing Intune app catalog and assignment state | Sync Apps from Intune and the scheduled Intune sync fail, so App Store doesn’t see your Intune apps or their assignments |
DeviceManagementApps.ReadWrite.All | Create and update Intune Win32 app deployments | Publishing, updates, rollbacks and assignment changes fail. Nothing is created or changed in Intune |
DeviceManagementConfiguration.Read.All | Read Intune assignment filters used by ring deployment settings | The assignment filter list in ring deployment settings shows No filters available |
DeviceManagementManagedDevices.Read.All | Read managed devices associated with the requesting user | App Store can’t read a requester’s devices, so an app assigned to devices can’t be targeted to one, and My Devices shows no devices |
Device.Read.All | Resolve an Entra device from its Azure AD Device ID. Group membership is added by directory object, so this is what lets any app assigned to devices reach the device, and what lets Group Automations add devices to a target group | A request for an app assigned to devices is approved, but the device never reaches the deployment group, so nothing installs. Group Automations report matched devices but add none |
Group.ReadWrite.All | Create and manage the security groups that drive app assignments | App Store can’t create deployment groups or add and remove members, so approved requests aren’t delivered |
GroupMember.Read.All | Resolve whether a user is in a group, which is how the admin, approver, portal access and app target groups are evaluated | Every group check fails and counts as “not a member”, so the Admin Group, approver groups, portal access group and request-on-behalf group grant nothing. The person who deployed App Store is still an administrator |
User.Read.All | Read user profiles, managers, and group memberships for approvals | User search, manager approvals and requests made on someone’s behalf fail |
Optional Permissions
Section titled “Optional Permissions”The script grants Mail.Send by default, because most organizations use email notifications. It grants the device check-in permission only when you ask for it, because that permission also allows wipe, retire, and rename.
| Permission | Used for | What doesn’t work without it | Default and parameter |
|---|---|---|---|
Mail.Send | Send email notifications from the mailbox you configure | No email notifications are sent: requests, approvals, reminders, escalations, installs and administrator events. Sending fails with 403 Forbidden. Teams notifications aren’t affected | Granted. -GrantMailSend $false leaves it off |
DeviceManagementManagedDevices.PrivilegedOperations.All | Ask a device to check in with Intune from the My Devices tab | Check in now isn’t offered, and the My Devices tab is read-only. Everything else on the tab works | Not granted. -GrantPrivilegedDeviceCheckIn $true grants it |
For example, to grant only the required permissions:
./Grant-AppStoreGraphPermissions.ps1 -ResourceGroupName "<resource group>" -AppServiceName "<appName>" -AppServicePrincipalId "<appServicePrincipalId>" -GrantMailSend $falseA permission the script doesn’t request isn’t removed if it’s already granted; the script says so. To add an optional permission later, run the script again with its parameter set to $true.
Device Check-In
Section titled “Device Check-In”The Check in now action on the My Devices tab asks a device to check in with Intune instead of waiting for its next scheduled check.
Three things have to be true before a user sees the button, so granting this permission on its own changes nothing users see:
- This permission is granted.
- Give users a My Devices tab is turned on in Store Administration.
- Let users ask a device to check in is turned on beneath it.
App Store detects whether the permission was granted. Without it the My Devices tab is read-only and the button is absent, rather than present and failing.
A user can ask for a check-in on a device where they are the Intune primary user, or on a device they are currently signed in to. Any other device answers the same way as one that does not exist. Every attempt is written to the audit log, refusals included, so you can see who asked for what.
To grant it, run the script again with the same three values and -GrantPrivilegedDeviceCheckIn $true: Microsoft Entra ID > Enterprise applications > All applications > (filter to Managed Identities) > your App Service > Permissions, then stop the App Service and start it. The My Devices tab returns to read-only.
Verify the Grant
Section titled “Verify the Grant”In the Azure portal, go to Microsoft Entra ID > Enterprise applications > All applications. Change the Application type filter to Managed Identities and find the App Service by name. Select it, then select Permissions in the left navigation. You should see nine Graph application permissions listed with admin consent granted: ten if you granted the device check-in permission, or eight if you left Mail.Send off.
You can also verify by signing in to the portal and selecting Admin, then Apps > App Management, and then Sync Apps from Intune. If apps appear, the permissions are in place.
Next Step
Section titled “Next Step”Continue to Add the production redirect URI.