Authentication using key in new library .Net v12 SDK

Shivane, Alka 1 Reputation point
2021-05-27T09:13:10.007+00:00

Earlier I was using .Net v11 SDK and below code was working fine.
Microsoft.Azure.Storage.Auth.StorageCredentials storageCredentials = new StorageCredentials(accountName, accountKey);
CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(
storageCredentials, new Uri(endpoint), null, null, null);
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer container = cloudBlobClient.GetContainerReference(containerName);
container.CreateIfNotExists();

Now in new .Net v12 SDK I am unable to find how to authenticate using storage key. There are other classes available but none works with Key now. Can you please tell me how to access container with this new SDK using Storage Key? Or is it mandatory to create Sas Token or client secrete?

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,368 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,096 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. deherman-MSFT 32,951 Reputation points Microsoft Employee
    2021-06-02T16:32:15.493+00:00

    @Shivane, Alka
    Apologies for the delayed response here and the inconvenience this has caused. Our SDK team has included some great samples on the GitHub page. Here is the section that will probably help you out:

                // Get a Storage account name, shared key, and endpoint Uri.  
                //  
                // You can obtain both from the Azure Portal by clicking Access  
                // Keys under Settings in the Portal Storage account blade.  
                //  
                // You can also get access to your account keys from the Azure CLI  
                // with:  
                //  
                //     az storage account keys list --account-name <account_name> --resource-group <resource_group>  
                //  
                string accountName = StorageAccountName;  
                string accountKey = StorageAccountKey;  
                Uri serviceUri = StorageAccountBlobUri;  
      
                // Create a SharedKeyCredential that we can use to authenticate  
                StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);  
      
                // Create a client that can authenticate with a connection string  
                BlobServiceClient service = new BlobServiceClient(serviceUri, credential);  
      
                // Make a service request to verify we've successfully authenticated  
                await service.GetPropertiesAsync();  
    

    Hope this helps! Let us know if you have further questions or issues.

    -------------------------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments