0
votes

I am not able to retrieve a secret from azure key vault to a .net console app which runs in azure windows VM. Below is the code i have used and i have given service principal all permission in key vault.

var kvc = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(
      async (string authority, string resource, string scope) => {
          var authContext = new AuthenticationContext(authority);
          var credential = new ClientCredential("App id, "secret identifier uri");

          AuthenticationResult result = await authContext.AcquireTokenAsync(resource, credential);
          if (result == null) {
              throw new InvalidOperationException("Failed to retrieve JWT token");
          }
          return result.AccessToken;
      }
  ));
1
Do you get an error? What is the error? - juunas

1 Answers

1
votes

Please reference this tutorial in the Microsoft documentation, where you can find the correct way to use Azure Key Vault inside a Windows VM, and using .NET. Note: In this solution, you will use Managed Service Identity, instead of the traditional Service Principal.