将 Azure AD 中的主体 ID 解析为用户、服务

Resolving principal id in Azure AD to User,Service

我正在尝试将主体 ID 列表解析为详细信息,例如 user/service 的名称。我有以下代码-

from azure.common.credentials import ServicePrincipalCredentials
from azure.graphrbac import GraphRbacManagementClient

TENANT = 'something.onmicrosoft.com'
TENANT_ID = '...'
CLIENT_ID = '...'
SECRET = '...'
List_of_Principal_IDs= ['...','...']
credentials = ServicePrincipalCredentials(
    client_id=CLIENT_ID,
    secret=SECRET,
    tenant=TENANT_ID,
    resource="https://graph.windows.net"
)
client = GraphRbacManagementClient(credentials, TENANT)

我尝试遵循 之一的建议,但我 运行 陷入了错误(见下文)。任何关于如何将这些主体 ID 解析为人类可理解格式的指导将不胜感激。

users = client.users.list(
         filter=f"principal_id eq '{List_of_Principal_IDs[0]}'"
     )
test = users.next()

错误-

azure.graphrbac.models.graph_error_py3.GraphErrorException: Property 'principal_id' does not exist as a declared property or extension property.

users = client.objects.get_objects_by_object_ids(List_of_Principal_IDs[0])
user = users.next()

错误-

msrest.exceptions.SerializationError: Unable to build a model: Unable to deserialize to object: type, AttributeError: 'str' object has no attribute 'get', DeserializationError: Unable to deserialize to object: type, AttributeError: 'str' object has no attribute 'get'

azure.graphrbac.models.graph_error_py3.GraphErrorException: Property 'principal_id' does not exist as a declared property or extension property.

关于这个错误,principal_idproperties of users. If I don't misunderstand, the principal_id means the Object ID of the user. But Object_id doesn't support filter, you need to use get method instead of list方法中不存在。

user = client.users.get(upn_or_object_id)

msrest.exceptions.SerializationError: Unable to build a model: Unable to deserialize to object: type, AttributeError: 'str' object has no attribute 'get', DeserializationError: Unable to deserialize to object: type, AttributeError: 'str' object has no attribute 'get'

get_objects_by_object_ids needs parameters of GetObjectsParameters class,但不只是一个列表。

objects = graphrbac_client.objects.get_objects_by_object_ids({
    'object_ids': [list of object ids],
    'types': [list of object types]
})