A hypothetical web-site currently connects using:
public SqlConnection CreateConnection()
{
DbConnection connection = new SqlConnection();
connection.Conne
What is the actual api?
We could use the GetSecret API to get value.
Preparation:
Registry Azure Active Directory application and assign Role
Steps:
1.Create KeyVault and add secret from Azure portal
2.Config Access policy
3.Get Access token
var context = new AuthenticationContext("https://login.windows.net/" + tenantId);
ClientCredential clientCredential = new ClientCredential(appId, secretKey);
var tokenResponse =await context.AcquireTokenAsync("https://vault.azure.net", clientCredential);
var accessToken = tokenResponse.AccessToken;
return accessToken;
Note: The resource for Keyvault is https://vault.azure.net
4.Test with Fiddler
We also can do that easily with SDK:
1.Create a console project and a Utils.cs file
public static string EncryptSecret { get; set; }
static string appId = "Application ID";
static string secretKey = "Secert key";
static string tenantId = "TenantId";
public static async Task GetAccessToken(string azureTenantId,string azureAppId,string azureSecretKey)
{
var context = new AuthenticationContext("https://login.windows.net/" + tenantId);
ClientCredential clientCredential = new ClientCredential(appId, secretKey);
var tokenResponse =await context.AcquireTokenAsync("https://vault.azure.net", clientCredential);
var accessToken = tokenResponse.AccessToken;
return accessToken;
}
2.Add the follow code in the main function and test it.
packages.config file
We also can get more information from CtrlDot mentioned document.