【发布时间】:2019-08-09 23:28:04
【问题描述】:
我需要使用 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 函数。
我在名为 AddRemoveAADUserByUPN() 的函数中找到了一个 .NET 示例: https://github.com/microsoft/azure-devops-dotnet-samples/blob/master/ClientLibrary/Samples/Graph/UsersSample.cs
GraphUserPrincipalNameCreationContext 是本示例中的一个接口。但是python不支持接口。
那么如何在python中实现呢?
【问题讨论】:
标签: python azure-devops azure-active-directory client