How to create azure instance to fetch storage account primary key in C#

Bhuvaneshwari Balasubramaniam 46 Reputation points

Hi Team, I am currently using Microsoft.Azure.Management.Fluent package to create azure instance for fetching storage account keys. Since this package is deprecated, can u recommend a solution? Below is the code:  var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(             clientId,             secertKey,             tennatId,             AzureEnvironment.AzureGlobalCloud); var azureInstance = Microsoft.Azure.Management.Fluent.Azure             .Configure()             .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)             .Authenticate(credentials).WithSubscription(subscription);

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,737 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,475 questions
Azure Managed Applications
Azure Managed Applications
An Azure service that enables managed service providers, independent software vendors, and enterprise IT teams to deliver turnkey solutions through the Azure Marketplace or service catalog.
113 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,798 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sumarigo-MSFT 44,001 Reputation points Microsoft Employee

    @Bhuvaneshwari Balasubramaniam Firstly, Apologies for the delay response! Welcome to Microsoft Q&A Forum, Thank you for posting your query here! Yes, the Microsoft.Azure.Management.Fluent package is deprecated. You can use the Azure.Identity package to authenticate and authorize access to Azure resources. Here is an example code snippet to authenticate and authorize access to Azure resources using the Azure.Identity package:

    using Azure.Identity;
    using Azure.Storage.Blobs;
    using System;
    string storageAccountName = "<your-storage-account-name>";
    string tenantId = "<your-tenant-id>";
    string clientId = "<your-client-id>";
    string clientSecret = "<your-client-secret>";
    var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
    var blobServiceClient = new BlobServiceClient(new Uri($"https://{storageAccountName}"), credential);
    var keys = blobServiceClient.Account.GetAccountInfo().Keys;
    foreach (var key in keys)
    }using Azure.Identity; using Azure.Security.KeyVault.Secrets; using Azure.Storage.Blobs; 

    In this example, we are using the DefaultAzureCredential class to authenticate and authorize access to Azure resources. The SecretClient class is used to retrieve the storage account key from the Azure Key Vault. Finally, we are using the BlobServiceClient class to interact with the storage account. Additional information: Manage storage account access keys

    If you get any error message or code, please share the screenshot. Please let us know if you have any further queries. I’m happy to assist you further. Please do not 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