I want to download a Blob from a private container in an Azure Storage Account from my local machine using Visual Studio (2022).
To achieve that I am using
DefaultAzureCredential credential = new DefaultAzureCredential();
Uri uri = new Uri("https://xxx.blob.core.windows.net/xxx/xxx.json");
BlobClient blobClient = new BlobClient(uri, credential);
Response<BlobDownloadResult> downloadResponse = blobClient.DownloadContent();
When I execute the code I get the following error
Issuer validation failed. Issuer did not match.
I authenticated in VS 2022 as described here: Managed Identity - how to debug locally
What do I need to do to successfully download the Blob?
CodePudding user response:
As described in https://docs.microsoft.com/en-us/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet DefaultAzureCredential tries different options to get a credential, and one of them is VisualStudioCredential.
For me to get it working locally I had to provide the VisualStudioTenantId:
DefaultAzureCredentialOptions defaultAzureCredentialOptions = new DefaultAzureCredentialOptions()
{
VisualStudioTenantId = "xxx"
};
DefaultAzureCredential credential = new DefaultAzureCredential(defaultAzureCredentialOptions);
Uri uri = new Uri("https://xxx.blob.core.windows.net/xxx/xxx.json");
BlobClient blobClient = new BlobClient(uri, credential);
Response<BlobDownloadResult> downloadResponse = blobClient.DownloadContent();