To consume the emulator in your application, you can either use the helper library or configure the standard Azure SDK clients manually.
Option 1: Using AzureKeyVaultEmulator.Client (Recommended)
Install the client package:
dotnet add package AzureKeyVaultEmulator.Client
Then inject the clients in your Program.cs. The library automatically retrieves the vaultUri from your connection strings (e.g., the one provided by Aspire).
var vaultUri = builder.Configuration.GetConnectionString("keyvault") ?? string.Empty;
// Basic implementation (Secrets only)
builder.Services.AddAzureKeyVaultEmulator(vaultUri);
// Or specify required services
builder.Services.AddAzureKeyVaultEmulator(vaultUri, secrets: true, keys: true, certificates: false);
If you prefer not to add the client library, you must manually configure ClientOptions to allow the use of localhost instead of a valid Azure domain.
var vaultUri = builder.Configuration.GetConnectionString("keyvault") ?? string.Empty;
// Disable verification to allow emulated URIs
var options = new SecretClientOptions { DisableChallengeResourceVerification = true };
builder.Services.AddTransient(s => new SecretClient(
new Uri(vaultUri),
new DefaultAzureCredential(),
options));
dotnet add package AzureKeyVaultEmulator.Client
// In Program.cs
var vaultUri = builder.Configuration.GetConnectionString("keyvault") ?? string.Empty;
builder.Services.AddAzureKeyVaultEmulator(vaultUri, secrets: true, keys: true, certificates: true);