Unable to connect to azure blob storage using InteractiveBrowserCredential

早过忘川 提交于 2020-03-03 07:04:57

问题


This code works just fine:

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)

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.

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'.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/60191090/unable-to-connect-to-azure-blob-storage-using-interactivebrowsercredential

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!