Skip to content

Instantly share code, notes, and snippets.

@ljtill
Last active December 6, 2019 16:10
Show Gist options
  • Select an option

  • Save ljtill/8fd86d8dda2643a740376f207cd32cbc to your computer and use it in GitHub Desktop.

Select an option

Save ljtill/8fd86d8dda2643a740376f207cd32cbc to your computer and use it in GitHub Desktop.
Provides the ability to retrieve a secret from Key Vault
private static async Task<string> GetSecret(string uri, string name)
{
/// <summary>
/// Secret retrieval via Managed Service Identity (MSI).
/// Link: https://docs.microsoft.com/en-us/azure/active-directory/managed-service-identity/overview
/// </summary>
AzureServiceTokenProvider provider = new AzureServiceTokenProvider();
KeyVaultClient client = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(provider.KeyVaultTokenCallback));
SecretBundle secret = await client.GetSecretAsync((uri + $"/Secrets/{name}"));
string value = secret.Value;
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment