Skip to content

Instantly share code, notes, and snippets.

@davidbreyer
Created October 10, 2019 18:17
Show Gist options
  • Save davidbreyer/6372376e70534a050fd30ef44aa2cf7f to your computer and use it in GitHub Desktop.
Save davidbreyer/6372376e70534a050fd30ef44aa2cf7f to your computer and use it in GitHub Desktop.
using Microsoft.Azure.KeyVault;
using Microsoft.Azure.Services.AppAuthentication;
using System;
using System.Threading.Tasks;
namespace YourNameSpace
{
public class VaultAccess
{
public async Task<string> GetSecretKey(string secretKeyEndPoint)
{
try
{
AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
KeyVaultClient keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
var secret = await keyVaultClient.GetSecretAsync(secretKeyEndPoint)
.ConfigureAwait(false);
return secret.Value;
}
catch (Exception)
{
return null;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment