如何获取 AAD 用户的 GraphUserPrincipalNameCreationContext?
How to get the GraphUserPrincipalNameCreationContext for an AAD user?
我需要使用 Azure DevOps REST API.
的 python 客户端库在 azure devops 中创建一个新用户
我写了下面的代码:
from azure.devops.connection import Connection
from azure.devops.v5_0.graph.models import GraphUserCreationContext
from msrest.authentication import BasicAuthentication
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
graph_client = connection.clients_v5_0.get_graph_client()
addAADUserContext = GraphUserCreationContext("anaya.john@mydomain.com")
print(addAADUserContext)
resp = graph_client.create_user(addAADUserContext)
print(resp)
我得到输出:
{'additional_properties': {}, 'storage_key': 'anaya.john@dynactionize.onmicrosoft.com'}
调用create_user方法时出错:
azure.devops.exceptions.AzureDevOpsServiceError: VS860015: Must have exactly one of originId or principalName set.
实际上我应该将 GraphUserPrincipalNameCreationContext 传递给 create_user 函数。
我找到了一个 .NET 示例,它在名为 AddRemoveAADUserByUPN() 的函数中执行此操作:
https://github.com/microsoft/azure-devops-dotnet-samples/blob/master/ClientLibrary/Samples/Graph/UsersSample.cs
GraphUserPrincipalNameCreationContext 是此示例中的一个接口。但是python不支持接口。
那么如何在 python 中实现呢?
某些 类,例如 GraphUserPrincipalNameCreationContext
目前在 python 客户端 API 中不可用。他们正在努力。您可以在 GitHub 存储库中跟踪此问题:
https://github.com/microsoft/azure-devops-python-api/issues/176
您可以使用 User Entitlements - Add REST API 代替 Graph API 用于 azure devops。为此,您可以使用以下 python 客户端:
您可以参考以下问题中给出的示例,了解如何使用提到的 python 客户端:
我需要使用 Azure DevOps REST API.
的 python 客户端库在 azure devops 中创建一个新用户我写了下面的代码:
from azure.devops.connection import Connection
from azure.devops.v5_0.graph.models import GraphUserCreationContext
from msrest.authentication import BasicAuthentication
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
graph_client = connection.clients_v5_0.get_graph_client()
addAADUserContext = GraphUserCreationContext("anaya.john@mydomain.com")
print(addAADUserContext)
resp = graph_client.create_user(addAADUserContext)
print(resp)
我得到输出:
{'additional_properties': {}, 'storage_key': 'anaya.john@dynactionize.onmicrosoft.com'}
调用create_user方法时出错:
azure.devops.exceptions.AzureDevOpsServiceError: VS860015: Must have exactly one of originId or principalName set.
实际上我应该将 GraphUserPrincipalNameCreationContext 传递给 create_user 函数。
我找到了一个 .NET 示例,它在名为 AddRemoveAADUserByUPN() 的函数中执行此操作: https://github.com/microsoft/azure-devops-dotnet-samples/blob/master/ClientLibrary/Samples/Graph/UsersSample.cs
GraphUserPrincipalNameCreationContext 是此示例中的一个接口。但是python不支持接口。
那么如何在 python 中实现呢?
某些 类,例如 GraphUserPrincipalNameCreationContext
目前在 python 客户端 API 中不可用。他们正在努力。您可以在 GitHub 存储库中跟踪此问题:
https://github.com/microsoft/azure-devops-python-api/issues/176
您可以使用 User Entitlements - Add REST API 代替 Graph API 用于 azure devops。为此,您可以使用以下 python 客户端:
您可以参考以下问题中给出的示例,了解如何使用提到的 python 客户端: