无法使用 InteractiveBrowserCredential 连接到 Azure Blob 存储 [英] Unable to connect to azure blob storage using InteractiveBrowserCredential

查看:30
本文介绍了无法使用 InteractiveBrowserCredential 连接到 Azure Blob 存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码运行良好:

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,填写我发出的代码,随后连接成功并返回容器列表.

I run it, I browse to the url, fill in the code I am issued and subsequently the connection is successful and a list of containers is returned.

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

However, when I try to switch to 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)

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

The browser does open, I get the token but the authentication fails with the following error:

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

网上看类似问题,根本原因通常是应用程序没有在Azure AD中注册为PublicClient.但是 - 这不是这里的情况.我确保该应用程序已注册为公共客户端.事实上 - 第一个样本完美地证明了这一点.

Looking at similar questions online, the root cause is usually that the application was not registered as a PublicClient in Azure AD. However - this is not the case here. I made sure that the application is registered as a public client. In fact - the first sample proves it perfectly.

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

I am banging my head here. Any other advice?

推荐答案

要使用InteractiveBrowserCredential,您需要在移动和桌面应用程序平台下添加重定向url,而不是网络平台.如果你在web平台下添加redirect url,你会遇到这个问题.

To use InteractiveBrowserCredential, you need to add a redirect url under Mobile and desktop applications platform, not web platform. If you added redirect url under web platform, you will encounter that issue.

您的代码运行良好.

这篇关于无法使用 InteractiveBrowserCredential 连接到 Azure Blob 存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆