Created
March 27, 2019 18:39
-
-
Save guitarrapc/661d4161655c44b9183060994c89d5f3 to your computer and use it in GitHub Desktop.
Create CloudQueueClient with Local and MSI
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
// 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