How to get the groups that an Azure application is in

Viewed 47

I can get the direct groups that an Azure user is in using this API. I want to get the direct groups that an Azure application is in. When I add an application into a group, it is displayed as a service principle. And I can see that there is an API to get direct memberOf list for a service principle. But I do not see an API that get the group list for an application. What am I missing?

1 Answers

To get the list of groups that an application is a memberOf, you can make use of below query by including microsoft.graph.group:

GET https://graph.microsoft.com/v1.0/servicePrincipals/<SP_objectID>/memberOf/microsoft.graph.group?$select=id,displayName,createdDateTime

I tried to reproduce the same in my environment and got the below results:

I have an Azure AD application named TestApp and added it to the groups like below:

enter image description here

Likewise, I added that application to Group2 and Group3 as well.

To get the list of groups that this application is a memberOf, I ran the below query and got results successfully as below:

GET https://graph.microsoft.com/v1.0/servicePrincipals/<SP_objectID>/memberOf/microsoft.graph.group?$select=id,displayName,createdDateTime

Response:

enter image description here

You can also use below query where you will get only list of group IDs that an application is a memberOf like below:

POST https://graph.microsoft.com/v1.0/servicePrincipals/<SP_objectID>/getMemberGroups

{
    "securityEnabledOnly": true
}

Response:

enter image description here

Related