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

查看:116
本文介绍了无法使用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 ,您需要在移动和桌面应用程序平台下添加重定向网址,而不是网络平台.如果在Web平台下添加了重定向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.

您的代码可以正常工作.

Your code works fine.

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

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