Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Explains why a request to Microsoft Graph failed with 403 Forbidden when the access token doesn't have the permissions required to call the API, and tells you which permission to add.
Plugin instance definition
{
"name": "GraphMissingPermissionsGuidancePlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll"
}
Configuration example
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v4.1.0/rc.schema.json",
"plugins": [
{
"name": "GraphMissingPermissionsGuidancePlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll"
}
],
"urlsToWatch": [
"https://graph.microsoft.com/v1.0/*",
"https://graph.microsoft.com/beta/*",
"https://graph.microsoft.us/v1.0/*",
"https://graph.microsoft.us/beta/*",
"https://dod-graph.microsoft.us/v1.0/*",
"https://dod-graph.microsoft.us/beta/*",
"https://microsoftgraph.chinacloudapi.cn/v1.0/*",
"https://microsoftgraph.chinacloudapi.cn/beta/*"
]
}
Configuration properties
None
Command line options
None
Remarks
The plugin analyzes responses from Microsoft Graph that return 403 Forbidden, including 403 Forbidden responses to individual requests in a $batch request. It skips responses that other plugins, such as mocking plugins, generated.
For each failed request, the plugin:
- Reads the delegated permissions (
scpclaim) or application permissions (rolesclaim) from the bearer token in theAuthorizationrequest header. - Looks up the permissions that allow calling the API using the Microsoft Graph DevX permissions API, which is the same service that the GraphMinimalPermissionsPlugin and GraphMinimalPermissionsGuidancePlugin use.
- Compares the permissions on the token with the permissions that the API accepts.
Because the plugin calls the Microsoft Graph DevX permissions API, it requires an internet connection. The plugin caches the retrieved permissions in memory for the lifetime of Dev Proxy. If the lookup doesn't complete within three seconds, or fails, the plugin can't determine the required permissions and retries the lookup for subsequent requests.
When the access token doesn't have any of the permissions that the API accepts, the plugin logs a failure that lists the permissions on the token, the least privileged permission to add, and higher-privileged alternatives. It also explains how to fix the issue, depending on whether the token contains delegated or application permissions. For example:
fail ╰ GraphMissingPermissionsGuidancePlugin: Request failed with 403 Forbidden because the access token doesn't have the permissions required to call GET /me/messages. Delegated permissions on the token: openid, User.Read. Add the least privileged permission: Mail.ReadBasic. Alternatively, use one of the following higher-privileged permissions: Mail.Read, Mail.ReadWrite. To fix it, add the permission to the delegated permissions of your app registration in Microsoft Entra ID, include it in the scopes your app requests when acquiring the access token, and make sure the user (or an administrator, for permissions that require admin consent) consents to it.
The plugin logs a warning instead when:
- The access token already has a permission that allows calling the API. In this case, the request likely failed for another reason, for example the user or app doesn't have access to the resource, a required license or administrative role is missing, or a policy restricts access to the resource.
- The plugin can't read permissions from the access token, for example because the request doesn't include a bearer token.
- The plugin can't determine which permissions the API requires.
The plugin also considers the following scenarios:
- Requests for other users: for delegated requests to
/users/{id}that don't target the signed-in user, the plugin doesn't treat theUser.ReadandUser.ReadWritepermissions as sufficient, because they only allow access to the signed-in user. If you're calling the API for the signed-in user, use/meinstead. - Shared mailboxes, calendars, and contacts: for delegated requests to another user's mail, calendar, or contacts, the plugin explains that the other user must share the data with the signed-in user, and that the app needs the corresponding
.Sharedpermission, such asMail.Read.Shared, or application permissions. - Personal Microsoft accounts: for delegated tokens issued to personal Microsoft accounts, the plugin uses the permissions supported for personal accounts.
If the plugin can't parse the request URL, for example when it uses the parenthesized key syntax like /users('id'), it shows a tip that it couldn't analyze the missing permissions.
The plugin is enabled in the microsoft-graph.json and m365.json preset configurations that ship with Dev Proxy.