【问题标题】:How to set correct privileges to use Python Azure SDK for Graph?如何设置正确的权限以使用 Python Azure SDK for Graph?
【发布时间】:2020-08-20 07:16:23
【问题描述】:

我正在尝试以编程方式将 reply_url 添加到 Azure 应用注册,但我收到了 GraphErrorException: Insufficient privileges to complete the operation

问题是我不明白我的应用注册需要哪些权限。

基本上我是在使用应用注册的凭据来更改它自己的reply_urls。

权限集是User.ReadApplication.ReadWrite.OwnedBy。两者都批准了。

我错过了哪一个?我怎样才能知道?

这是我正在使用的 SDK:azure-graphrbac==0.61.1

我的代码如下所示:

class GraphClient:
    def __init__(self, client_id, client_secret, tenant_id, object_id):
        self._credentials = ServicePrincipalCredentials(
            client_id=client_id,
            secret=client_secret,
            tenant=tenant_id,
            resource="https://graph.windows.net"
        )
        self._graph_client = GraphRbacManagementClient(
            credentials=self._credentials,
            tenant_id=tenant_id
        )
        self._application = self._graph_client.applications.get(object_id)

    def get_reply_urls(self) -> List[str]:
        return self._application.reply_urls

    def add_reply_url(self, reply_url) -> None:
        reply_urls: list = self.get_reply_urls()
        self._graph_client.applications.patch(
            self._application.app_id,
            ApplicationUpdateParameters(
                reply_urls=[
                    *reply_urls,
                    reply_url]
            )
        )

编辑:添加权限截图

【问题讨论】:

  • 您好,能否分享一下您添加的权限的屏幕截图(Azure 应用注册的“API 权限”选项卡)?
  • 请参考我下面提供的解决方案。

标签: python azure azure-ad-graph-api


【解决方案1】:

如果使用 microsoft graph,资源应该是:https://graph.microsoft.com

如果使用天蓝色广告图,资源应该是:https://graph.windows.net

根据你的代码,资源是https://graph.windows.net,所以它在后端请求azure ad graph api。 所以我们需要添加 azure ad graph 而不是 microsoft graph 的权限。

您提供的屏幕截图显示您添加了 microsoft graph 的权限 Application.ReadWrite.OwnedBy,但没有添加 azure ad graph。所以请删除它并添加属于 azure ad graph 的相同权限。

然后不要忘记授予管理员同意。

希望对你有帮助~

【讨论】:

  • 如果我只是更改资源以正确使用 Microsoft Graph 会怎样?我试了一下,得到一个azure.graphrbac.models.graph_error_py3.GraphErrorException: Your access token has expired. Please renew it before submitting the request. 错误。
  • @MoritzSchmitzv.Hülst 当我们使用这个python sdk时,资源似乎应该是https://graph.windows.net。我不知道我们是否可以更改资源,我认为最好的方法是更改​​权限但不更改资源。
  • 谢谢,它有效。现在我又得到了一个azure.graphrbac.models.graph_error_py3.GraphErrorException: Specified HTTP method is not allowed for the request target. 不同的主题,我猜。
  • @MoritzSchmitzv.Hülst 您能否为新问题创建另一个帖子并提供其详细信息(例如您在代码中使用的 sdk),我会尝试调查它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-16
  • 1970-01-01
  • 2021-04-20
  • 2015-11-14
  • 2021-04-29
  • 1970-01-01
  • 2013-11-30
相关资源
最近更新 更多