且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 Microsoft Graph API 检索 Azure AD 应用程序的用户详细信息和角色

更新时间:2023-11-24 19:20:22

个人,

您可以获取 appRoles 使用以下查询的 Azure AD 应用程序.

You can get the appRoles of an Azure AD application using the below query.

https://graph.microsoft.com/v1.0/serviceprincipals/07fce81e-8069-4ccb-9775-63f96d1f4e53

并检查 appRoles 属性.

and check the appRoles property.

您可以使用以下查询获取用户详细信息.

And you can get the user details using the below query.

https://graph.microsoft.com/v1.0/users/4ef105cc-508b-41c4-a5d2-7d41f2244c4c

您可以使用以下查询获取组详细信息.

And you can get the group details using the below query.

https://graph.microsoft.com/v1.0/groups/0023c709-3556-4296-a6ab-6df2a0a1113c

在你的情况下,你需要调用你指定的同一个调用

In your case you need to call the same call that you specified

https://graph.microsoft.com/v1.0/servicePrincipals/07fce81e-8069-4ccb-9775-63f96d1f4e53/appRoleAssignedTo

这将返回分配给应用角色的所有用户和组,您可以从这些 app 角色分配对象 如下所示,它们只不过是分配角色的用户的用户 ID,在组的情况下它是提供组详细信息的组的组 ID.

This will return all the users and groups assigned app roles and you can pull the principal id from these app role assignment objects as shown below which are nothing but the userid of the user that the role was assigned to and in the groups case its the group id of the group which gives the group details.

您可以通过 principaltype 区分用户和组,并据此调用上述 http 调用(用户或组)并获取这些详细信息.

You can differentiate user and group by principaltype and according to that you can call the above http calls(User or group) and get those details.

我们需要对重复的部分进行编码以避免它.

The duplicate ones need to be coded on our end to avoid it.

我的 JSON 数据示例:-

My Example JSON Data:-

For getting users and groups assigned app roles
GET https://graph.microsoft.com/v1.0/servicePrincipals/07fce81e-8069-4ccb-9775-63f96d1f4e53/appRoleAssignedTo
{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#servicePrincipals('07fce81e-8069-4ccb-9775-63f96d1f4e53')/appRoleAssignedTo",
    "value": [
        {
            "id": "zAXxTotQxEGl0n1B8iRMTPwz3O48iw9Oq3aFtqfYVjA",
            "deletedDateTime": null,
            "appRoleId": "00000000-0000-0000-0000-000000000000",
            "createdDateTime": "2020-06-01T19:21:01.4268687Z",
            "principalDisplayName": "Nishant Singh",
            "principalId": "4ef105cc-508b-41c4-a5d2-7d41f2244c4c",
            "principalType": "User",
            "resourceDisplayName": "testspaquestion",
            "resourceId": "07fce81e-8069-4ccb-9775-63f96d1f4e53"
        },
        {
            "id": "Y3tbwNOvDkqKK9yLxJ5wp2-uBAbApk9LoMs6AN_7iSs",
            "deletedDateTime": null,
            "appRoleId": "00000000-0000-0000-0000-000000000000",
            "createdDateTime": "2020-06-01T18:47:47.2702435Z",
            "principalDisplayName": "Sruthi J",
            "principalId": "c05b7b63-afd3-4a0e-8a2b-dc8bc49e70a7",
            "principalType": "User",
            "resourceDisplayName": "testspaquestion",
            "resourceId": "07fce81e-8069-4ccb-9775-63f96d1f4e53"
        },
        {
            "id": "CccjAFY1lkKmq23yoKERPBqNLldhOdBAm0lJzewK0Nk",
            "deletedDateTime": null,
            "appRoleId": "00000000-0000-0000-0000-000000000000",
            "createdDateTime": "2020-07-23T17:34:53.9538274Z",
            "principalDisplayName": "Bgroup",
            "principalId": "0023c709-3556-4296-a6ab-6df2a0a1113c",
            "principalType": "Group",
            "resourceDisplayName": "testspaquestion",
            "resourceId": "07fce81e-8069-4ccb-9775-63f96d1f4e53"
        }
    ]
}

查询完以上内容,拉取每条记录的principalid,根据principaltype相应调用user endpoint或group endpoint.

After querying the above, pull the principalid of each record and accordingly call user endpoint or group endpoint according to principaltype.

Get https://graph.microsoft.com/v1.0/users/4ef105cc-508b-41c4-a5d2-7d41f2244c4c //principalId

如果您有任何疑问,请告诉我.

Let me know if you have any queries.