Last active
February 17, 2020 08:49
-
-
Save danigian/97c5eae5a4a4cb37c2d7c8b3a7907b6c to your computer and use it in GitHub Desktop.
Storage authentication with Managed Identities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static async Task StorageTest() | |
{ | |
#region Using management SDK to get the keys. (to be used, for instance, with Event Host Processor) | |
var storManageCredentials = new Microsoft.Azure.Management.Storage.StorageManagementClient(tokenCredentials); | |
storManageCredentials.SubscriptionId = subscriptionId; | |
var accountsas = await storManageCredentials.StorageAccounts.ListKeysWithHttpMessagesAsync(resourceGroupName, storageAccountName); | |
var storCred = new StorageCredentials(resourceGroupName, accountsas.Body.Keys.FirstOrDefault().Value); | |
Console.WriteLine($"Primary key for storage account: {accountsas.Body.Keys.FirstOrDefault().Value}"); | |
#endregion | |
// #region Instantiating a containerClient directly | |
// //needs this for local development https://docs.microsoft.com/en-us/dotnet/api/azure.identity.environmentcredential?view=azure-dotnet | |
// //needs Storage Blob Data Owner (preview) permissions for the SP/MSI | |
// BlobContainerClient containerClient = new BlobContainerClient(new Uri($"https://{storageAccountName}.blob.core.windows.net/{storageContainerName}/"), | |
// new DefaultAzureCredential()); | |
// var listblobs = containerClient.GetBlobsAsync(); | |
// await foreach (var item in listblobs.AsPages()) | |
// { | |
// Console.WriteLine(string.Join(",",item.Values.Select(x=>x.Name))); | |
// } | |
// #endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment