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
1. Run the following command to restore packages for your project:
105
106
106
107
```dotnetcli
107
108
dotnet restore
108
109
```
110
+
109
111
1. Add a secret named *ConnectionStrings:AppConfig* to Secret Manager.
110
112
111
113
This secret contains the connection string to access your App Configuration store. Replace the value in the following command with the connection string for your App Configuration store.
@@ -130,7 +132,7 @@ The Secret Manager tool stores sensitive data for development work outside of yo
130
132
```
131
133
132
134
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `config.AddAzureAppConfiguration()` method.
133
-
135
+
134
136
> [!IMPORTANT]
135
137
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.0. Select the correct syntax based on your environment.
136
138
@@ -148,7 +150,7 @@ The Secret Manager tool stores sensitive data for development work outside of yo
148
150
```
149
151
150
152
#### [.NET Core 3.x](#tab/core3x)
151
-
153
+
152
154
```csharp
153
155
public static IHostBuilder CreateHostBuilder(string[] args) =>
154
156
Host.CreateDefaultBuilder(args)
@@ -160,6 +162,7 @@ The Secret Manager tool stores sensitive data for development work outside of yo
160
162
})
161
163
.UseStartup<Startup>());
162
164
```
165
+
163
166
---
164
167
165
168
1. Navigate to *<app root>/Views/Home* and open *Index.cshtml*. Replace its content with the following code:
@@ -116,50 +116,102 @@ To add a secret to the vault, you need to take just a few additional steps. In t
116
116
117
117
1. Run the following command to let the service principal access your key vault:
118
118
119
-
```
119
+
```cmd
120
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
121
121
```
122
122
123
-
1. Add secrets for *clientId* and *clientSecret* to Secrets Manager, the tool for storing sensitive data that you added to the *.csproj* file in [Quickstart: Create an ASP.NET Core app with Azure App Configuration](./quickstart-aspnet-core-app.md). These commands must be executed in the same directory as the *.csproj* file.
123
+
1. Add environment variables to store the values of *clientId*, *clientSecret*, and *tenantId*.
> These Key Vault credentials are used only within your application. Your application authenticates directly to Key Vault with these credentials. They are never passed to the App Configuration service.
149
+
---
150
+
151
+
> [!NOTE]
152
+
> These Key Vault credentials are used only within your application. Your application authenticates directly to Key Vault with these credentials. They are never passed to the App Configuration service.
153
+
154
+
1. Restart your terminal to load these new environment variables.
132
155
133
156
## Update your code to use a Key Vault reference
134
157
158
+
1. Add a reference to the required NuGet packages by running the following command:
159
+
160
+
```dotnetcli
161
+
dotnet add package Microsoft.Azure.KeyVault
162
+
dotnet add package Azure.Identity
163
+
```
164
+
135
165
1. Open *Program.cs*, and add references to the following required packages:
136
166
137
167
```csharp
138
168
using Microsoft.Azure.KeyVault;
139
-
using Microsoft.IdentityModel.Clients.ActiveDirectory;
169
+
using Azure.Identity;
140
170
```
141
171
142
172
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.
143
173
174
+
#### [.NET Core 2.x](#tab/core2x)
175
+
144
176
```csharp
145
177
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
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.
@@ -176,7 +228,7 @@ To add a secret to the vault, you need to take just a few additional steps. In t
0 commit comments