call key vault from logic app and azure function


Azure function –

using Microsoft.Azure.KeyVault;

using Microsoft.Azure.WebJobs;

using Microsoft.Azure.WebJobs.Extensions.Http;

using Microsoft.Azure.WebJobs.Host;

using Microsoft.IdentityModel.Clients.ActiveDirectory;

using System.Configuration;

using System.Net;

using System.Net.Http;

using System.Threading.Tasks;

namespace KeyVaultManagementFunctionApp


    public static class Runkva



        public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, “get”, “post”, Route =”HttpTriggerCSharp/vault/{vaultname}/secret/{secret}”)]HttpRequestMessage req, stringvaultname, string secret, TraceWriter log)


            // The Application Id of the Azure AD application

            var clientId = ConfigurationManager.AppSettings[“ClientId”];

            // The Value of the Key you created in the Azure AD application

            var clientSecret = ConfigurationManager.AppSettings[“ClientKey”];

            // Creating the Key Vault client

            var keyVault = new KeyVaultClient(async (authority, resource, scope) =>


                var authContext = new AuthenticationContext(authority);

                var credential = new ClientCredential(clientId, clientSecret);

                var token = await authContext.AcquireTokenAsync(resource, credential);

                return token.AccessToken;


            // base url of key vault

            var vaultUrl = $”https://{vaultname}”;

            // Retrieving the connection string from Key Vault

            var connectionstring = (await keyVault.GetSecretAsync(vaultUrl, secret)).Value;

            return req.CreateResponse(HttpStatusCode.OK, connectionstring);




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s