Prefix Key Vault Configuration Provider sample application (ASP.NET Core 1.x)
This sample illustrates the use of the Azure Key Vault Configuration Provider for ASP.NET Core 1.x using key name prefixes. For the ASP.NET Core 2.x sample, see Prefix Key Vault Configuration Provider sample application (ASP.NET Core 2.x).
[!NOTE] The configuration provider isn’t available for ASP.NET Core 1.0. If you want to implement the configuration provider and the app is an ASP.NET Core 1.0 app, upgrade the app to 1.1 or later first.
For more information on how the sample works, see the (xref:)Azure Key Vault configuration provider topic.
Using the sample
- Create a key vault and set up Azure Active Directory (Azure AD) for the application following the guidance in Get started with Azure Key Vault.
- Add secrets to the key vault using the Azure PowerShell Module, the Azure Management API, or the Azure Portal. Secrets are created as either Manual or Certificate secrets. Certificate secrets are certificates for use by apps and services but are not supported by the configuration provider. You should use the Manual option to create name-value pair secrets for use with the configuration provider.
- Hierarchical values (configuration sections) use
--(two dashes) as a separator. - For the sample app, create two Manual secrets with the following name-value pairs:
5000-AppSecret:5.0.0.0_secret_value5100-AppSecret:5.1.0.0_secret_value
- Hierarchical values (configuration sections) use
- Register the sample app with Azure Active Directory.
- Authorize the app to access the key vault. When you use the
Set-AzureRmKeyVaultAccessPolicyPowerShell cmdlet to authorize the app to access the key vault, provideListandGetaccess to secrets with-PermissionsToKeys list,get.
- Update the app’s appsettings.json file with the values of
Vault,ClientId, andClientSecret. - Run the sample app, which obtains its configuration values from
IConfigurationRootwith the same name as the prefixed secret name. In this sample, the prefix is the app’s version, which you provided to thePrefixKeyVaultSecretManagerwhen you added the Azure Key Vault configuration provider. The value forAppSecretis obtained withconfig["AppSecret"]. - Change the version of the app assembly in the project file from
5.0.0.0to5.1.0.0and run the app again. This time, the secret value returned is5.1.0.0_secret_value.
Comments (
)
)
Link to this page:
//www.vb-net.com/AspNet-DocAndSamples-2017/aspnetcore/security/key-vault-configuration/samples/key-name-prefix-sample/1.x/README.htm
|
|