AzureKeyVaultEmulator.Client 1.1.0

Additional Details

Trusted SSL is only supported from v2.2.0 or above, please upgrade your package.

There is a newer version of this package available.
See the version list below for details.
dotnet add package AzureKeyVaultEmulator.Client --version 1.1.0
                    
NuGet\Install-Package AzureKeyVaultEmulator.Client -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AzureKeyVaultEmulator.Client" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AzureKeyVaultEmulator.Client" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="AzureKeyVaultEmulator.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AzureKeyVaultEmulator.Client --version 1.1.0
                    
#r "nuget: AzureKeyVaultEmulator.Client, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=AzureKeyVaultEmulator.Client&version=1.1.0
                    
Install AzureKeyVaultEmulator.Client as a Cake Addin
#tool nuget:?package=AzureKeyVaultEmulator.Client&version=1.1.0
                    
Install AzureKeyVaultEmulator.Client as a Cake Tool

Overview

This library simplifies the inclusion of the Azure Key Vault Emulator into your local development environment.

You do not need to use it but it makes life easier. Due to the constraints of Azure Key Vault and the associated client libraries, any requests that don't come from https://*.vault.azure.net are rejected.

To work around this you need to set DisableChallengeResourceVerification = true for each client. This library does that for you, emulates the authentication and then dependency injects the clients you need.

Setup

First install the package to your application that needs to use Key Vault:

dotnet add package AzureKeyVaultEmulator.Client

Next you'll need to reference the vaultUri which points at the docker container.

If you're using .NET Aspire this will appear in your appsettings.json:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "myAspireResourceName": "<connectionstring will be populated here>"
  }
}

You don't need to add this into your appsettings.json beforehand, Aspire will do this for you.

If you're simply running the container locally and directly referencing it, you can find the port for https://localhost:{port} with the following:

docker ps

You'll then need to create a configuration item in your application which allows the dotnet runtime to get the https://localhost:{port}.

Usage

Including support for the emulator is simple:

// Injected by Aspire using the name "keyvault".
var vaultUri = builder.Configuration.GetConnectionString("keyvault") ?? string.Empty;

// Basic Secrets only implementation
builder.Services.AddAzureKeyVaultEmulator(vaultUri);

You can configure which Clients you want to expose like so:

builder.Services.AddAzureKeyVaultEmulator(vaultUri, secrets: true, keys: true, certificates: false);

By default only a SecretClient will be available, but you can easily add CertificateClient and KeyClient support.

Access

Now you've got your clients set up you can simply use them like you would any other DI service:

private SecretClient _secretClient;

public SecretsController(SecretClient secretClient)
{
    _secretClient = secretClient;
}

public async Task GetSecret(string name)
{
    var secret = await _secretClient.GetSecretAsync(name);
}

Quick Tip

To make life easy you can create an environment flag in your Program.cs to use the Emulator in a dev environment and the hosted Vault in production:

var vaultUri = builder.Configuration.GetConnectionString("keyvault") ?? string.Empty;

if(builder.Environment.IsDevelopment())
    builder.Services.AddAzureKeyVaultEmulator(vaultUri, secrets: true, certificates: true, keys: true);
else
    builder.Services.AddAzureClients(client =>
    {
        var asUri = new Uri(vaultUri);

        client.AddSecretClient(asUri);
        client.AddKeyClient(asUri);
        client.AddCertificateClient(asUri);
    });
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.