Search code examples
azureclientstorageazure-keyvaultsecret-key

SecretClient - get secret from azure KeyVault


I want to get the value of a secret in keyvault in Azure, I saw that I can create a SecretClient like this: var client = new SecretClient(new Uri(kvUri), new ClientSecretCredential(tenantId, clientId, clientSecret));

how do I know the value to give the constructor? where can I found the clientId, ClientSecret and the kvUri?

Thanks!


Solution

  • You need to create an application for access first when using ClientSecretCredential.

    Navigate to Azure Active Directory -> App registrations -> New registration

    tenantId and clientId are in the "Overview" :

    enter image description here

    clientSecret is in "Certificates & secrets":

    enter image description here

    Note: After creating the application, you must add access policy in key vault for the application.

    enter image description here