You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/use-key-vault-references-dotnet-core.md
+26-23Lines changed: 26 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,15 +20,17 @@ ms.custom: mvc
20
20
---
21
21
# Tutorial: Use Key Vault references in an ASP.NET Core app
22
22
23
-
In this tutorial, you learn how to use the Azure App Configuration service together with Azure Key Vault. These are complementary services which are used side by side in most application deployments.
23
+
In this tutorial, you learn how to use the Azure App Configuration service together with Azure Key Vault. App Configuration and Key Vault are complementary services used side by side in most application deployments.
24
24
25
-
To help you use the services together, App Configuration can create keys that reference values stored in Key Vault. When App Configuration does this, it stores the URI to the Key Vault value rather than the value itself. Your application retrieves the value of this key using the App Configuration client provider, just like it does for any other key stored in App Configuration. The client provider recognizes the key as a Key Vault reference and uses Key Vault to retrieve the value.
25
+
App Configuration helps you use the services together by creating keys that reference values stored in Key Vault. When App Configuration creates such keys, it stores URIs to Key Vault values rather than the values themselves.
26
+
27
+
Your application uses the App Configuration client provider to retrieve the Key Vault values, just as it does for any other keys stored in App Configuration. Because the client provider recognizes the keys as Key Vault references, it uses Key Vault to retrieve their values.
26
28
27
29
Your application is responsible for authenticating properly to both App Configuration and Key Vault. The two services don't communicate directly.
28
30
29
-
This tutorial shows how you can implement Key Vault references in your code. It builds on the web app introduced in the quickstarts. Before you continue, finish [Create an ASP.NET Core app with App Configuration](./quickstart-aspnet-core-app.md) first.
31
+
This tutorial shows you how to implement Key Vault references in your code. It builds on the web app introduced in the quickstarts. Before you continue, finish [Create an ASP.NET Core app with App Configuration](./quickstart-aspnet-core-app.md) first.
30
32
31
-
You can use any code editor to do the steps in this tutorial. [Visual Studio Code](https://code.visualstudio.com/) is an excellent cross-platform app that's available for the Windows, macOS, and Linux operating systems.
33
+
You can use any code editor to do the steps in this tutorial. For example, [Visual Studio Code](https://code.visualstudio.com/) is a cross-platform code editor that's available for the Windows, macOS, and Linux operating systems.
32
34
33
35
In this tutorial, you learn how to:
34
36
@@ -44,14 +46,14 @@ Before you start this tutorial, install the [.NET Core SDK](https://dotnet.micro
44
46
45
47
## Create a vault
46
48
47
-
1. Select the **Create a resource** option in the upperleft corner of the Azure portal
49
+
1. Select the **Create a resource** option in the upper-left corner of the Azure portal.
48
50
49
51

50
-
1.Go to Search and enter **Key Vault**.
52
+
1.In the search box, enter **Key Vault**.
51
53
1. From the results list, select **Key Vault**.
52
-
1.In the **Key Vault**section, select **Create**.
53
-
1.In the **Create key vault**section, provide the following information:
54
-
-A unique name is required. In the **Name** box, enter **Contoso-vault2**.
54
+
1.On the **Key Vault**pane, select **Create**.
55
+
1.On the **Create key vault**pane, provide the following information:
56
+
- In the **Name** box, enter **Contoso-vault2**. The name must be unique.
55
57
- In **Subscription**, choose a subscription.
56
58
- Under **Resource Group**, select **Create new** and enter a resource group name.
57
59
- In the **Location** drop-down menu, choose a location.
@@ -64,7 +66,7 @@ At this point, your Azure account is the only one authorized to access this new
64
66
65
67
## Add a secret to Key Vault
66
68
67
-
To add a secret to the vault, you just need to take a couple of additional steps. In this case, add a message that you can use to test Key Vault retrieval. The message is called **Message** and you store the value of **Hello from Key Vault** in it.
69
+
To add a secret to the vault, you need to take just a few additional steps. In this case, add a message that you can use to test Key Vault retrieval. The message is called **Message**, and you store the value "Hello from Key Vault" in it.
68
70
69
71
1. On the **Key Vault** properties pages, select **Secrets**.
70
72
1. Select **Generate/Import**.
@@ -77,13 +79,13 @@ To add a secret to the vault, you just need to take a couple of additional steps
77
79
78
80
## Add a Key Vault reference to App Configuration
79
81
80
-
1. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the app configuration store instance that you created in the quickstart.
82
+
1. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the App Configuration store instance that you created in the quickstart.
81
83
82
84
1. Select **Configuration Explorer**.
83
85
84
86
1. Select **+ Create** > **Key vault reference**, and then enter or select the following values:
-**Subscription**, **Resource group**, and **Key vault**: Enter the values corresponding to those in the key vault you created in the previous section.
88
90
-**Secret**: Select the secret named **Message** that you created in the previous section.
89
91
@@ -95,7 +97,7 @@ To add a secret to the vault, you just need to take a couple of additional steps
95
97
az ad sp create-for-rbac -n "http://mySP" --sdk-auth
96
98
```
97
99
98
-
This operation will return the following series of key/value pairs:
100
+
This operation returns the following series of key/value pairs:
99
101
100
102
```console
101
103
{
@@ -118,7 +120,7 @@ To add a secret to the vault, you just need to take a couple of additional steps
118
120
az keyvault set-policy -n <your-unique-keyvault-name> --spn <clientId-of-your-service-principal> --secret-permissions delete get list set --key-permissions create decrypt delete encrypt get list unwrapKey wrapKey
119
121
```
120
122
121
-
1. Add secrets for *clientId* and *clientSecret* to Secrets Manager. These commands must be executed in the same directory as the *.csproj* file.
123
+
1. In the following commands, add secrets in place of *clientId* and *clientSecret* to Secrets Manager. The commands must be run in the same directory as the *.csproj* file.
122
124
123
125
```
124
126
dotnet user-secrets set ConnectionStrings:KeyVaultClientId <clientId-of-your-service-principal>
@@ -130,14 +132,14 @@ To add a secret to the vault, you just need to take a couple of additional steps
130
132
131
133
## Update your code to use a Key Vault reference
132
134
133
-
1. Open *Program.cs*, and add references to the required packages.
135
+
1. Open *Program.cs*, and add references to the following required packages:
134
136
135
137
```csharp
136
138
using Microsoft.Azure.KeyVault;
137
139
using Microsoft.IdentityModel.Clients.ActiveDirectory;
138
140
```
139
141
140
-
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `config.AddAzureAppConfiguration` method. Include the `UseAzureKeyVault` option, passing in a new `KeyVaultClient` reference to your Key Vault.
142
+
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `config.AddAzureAppConfiguration` method. Include the `UseAzureKeyVault` option to pass in a new `KeyVaultClient` reference to your Key Vault.
141
143
142
144
```csharp
143
145
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
@@ -160,7 +162,9 @@ To add a secret to the vault, you just need to take a couple of additional steps
160
162
.UseStartup<Startup>();
161
163
```
162
164
163
-
1. After you've passed the `KeyVaultClient` reference to the `UseAzureKeyVault` method when initializing the connection to App Configuration, you can access the values of Key Vault references in the same way you access the values of regular App Configuration keys. To see this process in action, open *Index.cshtml* in the **Views** > **Home** directory. Replace its contents with the following code:
165
+
1. When you initialized the connection to App Configuration, you passed the `KeyVaultClient` reference to the `UseAzureKeyVault` method. After the initialization, you can access the values of Key Vault references in the same way you access the values of regular App Configuration keys.
166
+
167
+
To see this process in action, open *Index.cshtml* in the **Views** > **Home** folder. Replace its contents with the following code:
164
168
165
169
```html
166
170
@using Microsoft.Extensions.Configuration
@@ -180,7 +184,7 @@ To add a secret to the vault, you just need to take a couple of additional steps
180
184
and @Configuration["TestApp:Settings:KeyVaultMessage"]</h1>
181
185
```
182
186
183
-
You access the value of the Key Vault reference "TestApp:Settings:KeyVaultMessage" in the same way as the configuration value for "TestApp:Settings:Message".
187
+
You access the value of the Key Vault reference **TestApp:Settings:KeyVaultMessage** in the same way as for the configuration value of **TestApp:Settings:Message**.
184
188
185
189
## Build and run the app locally
186
190
@@ -190,24 +194,23 @@ To add a secret to the vault, you just need to take a couple of additional steps
190
194
dotnet build
191
195
```
192
196
193
-
2. After the build is successfully completed, run the following command to run the web app locally:
197
+
1. After the build is successfully completed, use the following command to run the web app locally:
194
198
195
199
```
196
200
dotnet run
197
201
```
198
202
199
-
3. Open a browser window, and go to `http://localhost:5000`, which is the default URL for the web app hosted locally.
In this tutorial, you added an Azuremanaged service identity to streamline access to App Configuration and improve credential management for your app. To learn more about how to use App Configuration, continue to the Azure CLI samples.
213
+
In this tutorial, you added an Azure-managed service identity to streamline access to App Configuration and to improve credential management for your app. To learn more about how to use App Configuration, continue to the Azure CLI samples.
0 commit comments