Do I need additional data to generate ConnectionString?
Preparation:
1.Registry an app in the Azure AD and create service principal for accessing the resource. More detail please refer to the document.
2.Prepare the authentication file with the content as following format. The values can be got from the step 1.
subscription=########-####-####-####-############
client=########-####-####-####-############
key=XXXXXXXXXXXXXXXX
tenant=########-####-####-####-############
managementURI=https\://management.core.windows.net/
baseURL=https\://management.azure.com/
authURL=https\://login.windows.net/
graphURL=https\://graph.windows.net/
3.Install the libraries Microsoft.Azure.Management.Fluent and Microsoft.Azure.Management.ResourceManager.Fluent in the project
Demo Code:
var credFile = @"auth file path"; // example: c:\tom\auth.txt
var keyName = "key1";
var azure = Azure
.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithDefaultSubscription();
var storageAccount = azure.StorageAccounts.GetByResourceGroup(resourceGroupName, storageName);
var key = storageAccount.RegenerateKey(keyName);
var connectionString = $"DefaultEndpointsProtocol=http;AccountName={storageAccount.Name};AccountKey={key.FirstOrDefault()?.Value}";
Test Result:
