python-3.x - 无法使用 InteractiveBrowserCredential 连接到 azure blob 存储

标签 python-3.x azure azure-active-directory azure-blob-storage

这段代码工作得很好:

from azure.storage.blob import BlobServiceClient
from azure.identity import InteractiveBrowserCredential, DeviceCodeCredential, ClientSecretCredential

credential = DeviceCodeCredential(authority="login.microsoftonline.com", tenant_id="***", client_id="***")

blobber = BlobServiceClient(account_url="https://***.blob.core.windows.net", credential=credential)

blobs = blobber.list_containers()
for b in blobs:
    print(b)

我运行它,浏览到 URL,填写我发出的代码,随后连接成功并返回容器列表。

但是,当我尝试切换到 InteractiveBrowserCredential 时:

credential = InteractiveBrowserCredential(authority="login.microsoftonline.com", tenant_id="***", client_id="***")

blobber = BlobServiceClient(account_url="https://***.blob.core.windows.net", credential=credential)

blobs = blobber.list_containers()
for b in blobs:
    print(b)

浏览器确实打开,我获得了 token ,但身份验证失败并出现以下错误:

azure.core.exceptions.ClientAuthenticationError: Authentication failed: AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.

网上看类似问题,根本原因通常是应用程序没有在Azure AD中注册为PublicClient。然而,这里的情况并非如此。我确保该应用程序已注册为公共(public)客户端。事实上,第一个样本就完美地证明了这一点。

我在这里敲头。还有其他建议吗?

最佳答案

要使用InteractiveBrowserCredential,您需要在移动和桌面应用程序平台而非网络平台下添加重定向网址。如果您在 Web 平台下添加了重定向 url,则会遇到该问题。

enter image description here

您的代码运行良好。

enter image description here

关于python-3.x - 无法使用 InteractiveBrowserCredential 连接到 azure blob 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60191090/

相关文章:

python - 如何让对象属性在 Python 中动态更新

Azure - 虚拟网络网关与 VPN 网关

java - 无法在 Azure 表实体中创建字节字段

azure - 在 Azure 函数中启用 App Insights 探查器

Azure静态Web应用程序生成的envs和azure AD租户回复url

Python 套接字数据返回 <byte> 对象。如何正则表达式它?

python - 对每个数据帧行中的列表求和

symfony - 尝试登录时陷入循环

azure - 使用 ARM 模板和 Key Vault 创建 Azure SQL 的最佳实践是什么

python-3.x - 如何在.kv文件中实现for循环