The Azure port still uses the Azure AD Graph API in some places. One thing it uses this for is to list API permissions. For this, the portal uses the REST API target GET https://graph.windows.net/myorganization/applicationRefs/c5393580-f805-4401-95e8-94b7a6ef2fc2?api-version=2.0 (example shown for Office 365 Management API). I've searched and cannot seem to find a way to list similar permission sets using the Microsoft Graph API. Is there a way to access this using the Microsoft Graph API?
Microsoft Graph API support for applicationRefs information
551 Views Asked by mike_b AtThere are 2 best solutions below
On
Ok, was going to upvote one of the previous answers, but my profile is too new. :( You can do this by reading the MS Graph service principal in your tenant as described above. This PowerShell code gives an example (it's used in a command called Find-GraphPermission in the autographps and autographps-sdk modules.
Basic approach is:
- Get app-only permissions from the
appRolesproperty of theservicePrincipal - Get delegated permissions from the
publishedPermissionScopesproperty - Each element of
appRoleshas an id that can be read or written from a givenappRoleAssigmentobject on an app'sservicePrincipalin your tenant. Note that eachappRoleelement has avalueproperty that is the common friendly name of the app-only permission (e.g.BitlockerKey.ReadBasic.All - A similar
idandvaluepair exists for each element ofpublishedPermissionScopeswhich gives you the delegated permissions. You can use those ids withoauth2PermissionGrantobjects under the segment/oauth2PermissionGrantsto enumerate consent grants for a givenservicePrincipal(and thusapp) in your tenant or grant or remove consent
Note that the ids for both appRoles and publishedPermissionScopes are the same in all tenants, so you can actually perform this same mapping of friendly names to ids for any tenant, and use a static snapshot. This can be useful as your application may not be able to read the Microsoft Graph servicePrincipal object. If you store a static version, you'll have the mapping regardless and you'll only miss any new permissions that get added to Microsoft Graph for new APIs.
This file contains a snapshot of the MS Graph servicePrincipal as a fairly readable JSON-like PowerShell hash table: https://github.com/adamedx/autographps-sdk/blob/main/src/common/DefaultScopeData.ps1
For this requirement, you can use this microsoft graph api:
https://graph.microsoft.com/v1.0/applications/<object id of the application>It will response the result like below screenshot(please pay attention to the field
requiredResourceAccess):The content under
requiredResourceAccessis the API permissions of this application. The typescopemeans the permission is Delegated type and the typerolemeans the permission is Application type.Then please refer to steps below to know which permission does the
idunderresourceAccessfield refer to.Copy the
resourceAppId, in my screenshot is00000003-0000-0000-c000-000000000000. And request the graph api:https://graph.microsoft.com/v1.0/serviceprincipals?$filter=appId eq '00000003-0000-0000-c000-000000000000'Copy one of the
idunderresourceAccessfield in the response of first graph api. For example copy the first ida154bxxxxxxxxxxx59in my first screenshot. And then search this id in the response of second graph api, we can find this id refer toUser.Read.Allpermission.