【问题标题】:How to get the GraphUserPrincipalNameCreationContext for an AAD user?如何获取 AAD 用户的 GraphUserPrincipalNameCreationContext?
【发布时间】: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


    【解决方案1】:

    GraphUserPrincipalNameCreationContext 这样的一些类目前在python 客户端API 中不可用。他们正在努力。您可以在 GitHub 存储库中跟踪问题: https://github.com/microsoft/azure-devops-python-api/issues/176

    您可以将 用户权利 - 添加 REST API 用于 azure devops,而不是使用 Graph API。为此,您可以使用以下 python 客户端:

    https://github.com/microsoft/azure-devops-python-api/tree/dev/azure-devops/azure/devops/v5_0/member_entitlement_management

    您可以参考以下问题中给出的示例来了解如何使用上述python客户端:

    Unable to deserialize to object: type, KeyError: ' key: int; value: str '

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-15
      • 2017-07-25
      • 1970-01-01
      • 2019-04-18
      • 2020-11-13
      • 1970-01-01
      • 1970-01-01
      • 2015-06-27
      相关资源
      最近更新 更多