Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created March 27, 2019 18:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save guitarrapc/661d4161655c44b9183060994c89d5f3 to your computer and use it in GitHub Desktop.
Create CloudQueueClient with Local and MSI
// For local Auth with ConnectionString (temporary workaround)
private static CloudQueueClient CreateQueueClient(string connectionString)
{
var account = CloudStorageAccount.Parse(connectionString);
var queueClient = account.CreateCloudQueueClient();
return queueClient;
}
// For MSI Auth
private static async Task<CloudQueueClient> CreateQueueClientAsync(string storageAccountName)
{
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var accessToken = await azureServiceTokenProvider.GetAccessTokenAsync("https://storage.azure.com/");
var tokenCredential = new TokenCredential(accessToken);
var storageCredentials = new StorageCredentials(tokenCredential);
var queueClient = new CloudQueueClient(new StorageUri(new Uri($"https://{storageAccountName}.queue.core.windows.net")), storageCredentials);
return queueClient;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment