0
votes

I have a requirement to read the secrets/values from Azure key vault using clientId, clientSecret, TenantId, and vaultURL. I have values for all of these. I need to read the values stored on azure key vault using these values.

Any help with the code?

2

2 Answers

0
votes

Wanted to share these as well ( I see the one person answered ) just so you have them as well

https://docs.microsoft.com/en-us/azure/key-vault/general/developers-guide

and

https://www.microsoft.com/en-us/download/details.aspx?id=45343 to grab the samples

0
votes

If you want a sample you could refer to this tutorial: Azure Key Vault client library for .NET. And below is my test code.

            string clientSecret = "client secret";
            string clientId = "client id";

            var secreturi = "https://****.vault.azure.net";

            KeyVaultClient kvClient = new KeyVaultClient(async (authority, resource, scope) =>
            {
                var adCredential = new ClientCredential(clientId, clientSecret);
                var authenticationContext = new AuthenticationContext(authority, null);
                return (await authenticationContext.AcquireTokenAsync(resource, adCredential)).AccessToken;
            });
            var keyvaultSecret = await kvClient.GetSecretAsync($"{secreturi}", "testsecret").ConfigureAwait(false);

            Console.Write(keyvaultSecret.Value);

enter image description here