Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.