There are many way to interact with a storage account in Azure. The first and easiest way would be to use a connection string which acts as credentials. However this approach does not follow best practices as you will need to hard code credentials or pass them as a parameter in your application. Based on the well architected framework the most reliable and secure way to communicate between resources in Azure would be the managed Identity and you can read more about how it works in the below URL.
Managed identities for Azure resources – Microsoft Entra | Microsoft Learn
The code provided in this article can be used to authenticate with Managed Identity in a storage account. Given that you have already provided the necessary RBAC between your services, you can use the below example code to list blobs in a storage account.
private static async Task ListBlobsFlatListing(BlobContainerClient blobContainerClient, int? segmentSize) { try { // Call the listing operation and return pages of the specified size. var resultSegment = blobContainerClient.GetBlobsAsync() .AsPages(default, segmentSize); // Enumerate the blobs returned for each page. await foreach (Page<BlobItem> blobPage in resultSegment) { foreach (BlobItem blobItem in blobPage.Values) { Console.WriteLine("Blob name: {0}", blobItem.Name); } Console.WriteLine(); } } catch (RequestFailedException e) { Console.WriteLine(e.Message); Console.ReadLine(); throw; } }
https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blobs-list
In order to authenticate with MI you will need to create a new BlobContainerClient with your storage-account-name and pass in the parameters the ManagedIdentity as the credentials method. Then you will be able to use your ListBlob function that is provided from Microsoft using the client previously created.
BlobContainerClient client = new BlobContainerClient(new Uri($"https://storage-account-name.blob.core.windows.net/testing"), new ManagedIdentityCredential()); ListBlobsFlatListing(client, 1).GetAwaiter().GetResult();
After these steps you will be able to fetch data using Managed identity instead of classic authentication.