我正在尝试将主体 ID 列表解析为用户/服务名称等详细信息。我有以下代码 -
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)
我尝试遵循 stackoverflow pages 之一的建议但我遇到了错误(见下文)。任何有关我如何将这些主要 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.
关于此错误,properties of users中不存在principal_id
。如果我没理解错的话,principal_id
是指用户的Object ID
。但Object_id不支持filter
,需要使用 get方法而不是 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需要GetObjectsParameters
的参数类,但不仅仅是一个列表。
objects = graphrbac_client.objects.get_objects_by_object_ids({
'object_ids': [list of object ids],
'types': [list of object types]
})
关于python-3.x - 将 Azure AD 中的主体 ID 解析为用户、服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64866364/