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

问题描述 投票:1回答:1

我试图在 Azure 应用程序注册中以编程方式添加 reply_url,但我收到了以下信息。GraphErrorException: Insufficient privileges to complete the operation.

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

基本上,我是用app注册的凭证来改变自己的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]
            )
        )

编辑:添加了权限截图enter image description here

python azure azure-ad-graph-api
1个回答
1
投票

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

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

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

你提供的截图显示你添加了以下权限 Application.ReadWrite.OwnedBy 微软图形的,但不是蔚蓝广告图。因此,请删除它,并添加相同的权限,属于蔚蓝广告图。enter image description here

enter image description here

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

enter image description here

希望能帮到你~

© www.soinside.com 2019 - 2024. All rights reserved.