繁体   English   中英

如何设置正确的权限以使用 Python Azure SDK 用于 Graph?

[英]How to set correct privileges to use Python Azure SDK for Graph?

我正在尝试以编程方式将 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]
            )
        )

编辑:添加权限截图在此处输入图像描述

如果使用 microsoft graph,则资源应为: https://graph.microsoft.com

如果使用 azure 广告图,则资源应为: https://graph.windows.net

根据您的代码,资源是https://graph.windows.net ,因此它在后端请求 azure 广告图 api 。 所以我们需要添加 azure 广告图而不是微软图的权限。

您提供的屏幕截图显示您添加了 microsoft graph 的Application.ReadWrite.OwnedBy权限,但没有添加 azure ad graph 的权限。 所以请删除它并添加属于 azure 广告图的相同权限。 在此处输入图像描述

在此处输入图像描述

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

在此处输入图像描述

希望有帮助~

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM