-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAzureKeyVaultProvider.cs
33 lines (30 loc) · 1.04 KB
/
AzureKeyVaultProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Microsoft.Azure.Services.AppAuthentication;
using System.Configuration;
using System;
using System.Threading.Tasks;
using Microsoft.Azure.KeyVault;
using Microsoft.Azure.WebJobs.Host;
using System.Net.Http;
namespace CMGBooker
{
public class AzureKeyVaultProvider
{
private static HttpClient client = new HttpClient();
public static async Task<string> GetSecret(string id, TraceWriter log)
{
try
{
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var callback = new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback);
var kvClient = new KeyVaultClient(callback, client);
var url = $"{ConfigurationManager.AppSettings["KeyVaultUri"]}secrets/{id}";
return (await kvClient.GetSecretAsync(url)).Value;
}
catch (Exception ex)
{
log.Error(ex.ToString());
return null;
}
}
}
}