Vit*_*liy 6 azure python-3.x 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)
Run Code Online (Sandbox Code Playgroud)
我运行它,浏览到 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)
Run Code Online (Sandbox Code Playgroud)
浏览器确实打开,我获得了令牌,但身份验证失败并出现以下错误:
azure.core.exceptions.ClientAuthenticationError: Authentication failed: AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.
Run Code Online (Sandbox Code Playgroud)
网上看类似的问题,根本原因通常是应用程序没有在Azure AD中注册为PublicClient。然而,这里的情况并非如此。我确保该应用程序已注册为公共客户端。事实上,第一个样本就完美地证明了这一点。
我在这里敲头。还有其他建议吗?
要使用InteractiveBrowserCredential,您需要在移动和桌面应用程序平台(而不是Web平台)下添加重定向 url。如果您在 Web 平台下添加了重定向 url,则会遇到该问题。
你的代码工作正常。
| 归档时间: |
|
| 查看次数: |
3244 次 |
| 最近记录: |