Skip to content

Commit c1e1995

Browse files
authored
Merge pull request #101865 from lisaguthrie/newconfigprovider
updating for newest config provider
2 parents d158551 + 31a7422 commit c1e1995

File tree

4 files changed

+77
-22
lines changed

4 files changed

+77
-22
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-aspnet-core.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Before you continue, finish [Create an ASP.NET Core app with App Configuration](
5050
1. Add a reference to the `Microsoft.Azure.AppConfiguration.AspNetCore` NuGet package by running the following command:
5151

5252
```CLI
53-
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore --version 3.0.0-preview-010560002-1165
53+
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore --version 3.0.0-preview-011100002-1192
5454
```
5555
5656
1. Open *Program.cs*, and update the `CreateWebHostBuilder` method to add the `config.AddAzureAppConfiguration()` method.

articles/azure-app-configuration/quickstart-aspnet-core-app.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: jpconnock
77
ms.service: azure-app-configuration
88
ms.devlang: csharp
99
ms.topic: quickstart
10-
ms.date: 01/04/2020
10+
ms.date: 01/21/2020
1111
ms.author: jeconnoc
1212

1313
#Customer intent: As an ASP.NET Core developer, I want to learn how to manage all my app settings in one place.
@@ -99,13 +99,15 @@ The Secret Manager tool stores sensitive data for development work outside of yo
9999
1. Add a reference to the `Microsoft.Azure.AppConfiguration.AspNetCore` NuGet package by running the following command:
100100

101101
```dotnetcli
102-
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore --version 3.0.0-preview-010560002-1165
102+
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore --version 3.0.0-preview-011100002-1192
103103
```
104+
104105
1. Run the following command to restore packages for your project:
105106
106107
```dotnetcli
107108
dotnet restore
108109
```
110+
109111
1. Add a secret named *ConnectionStrings:AppConfig* to Secret Manager.
110112
111113
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
130132
```
131133
132134
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `config.AddAzureAppConfiguration()` method.
133-
135+
134136
> [!IMPORTANT]
135137
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.0. Select the correct syntax based on your environment.
136138
@@ -148,7 +150,7 @@ The Secret Manager tool stores sensitive data for development work outside of yo
148150
```
149151
150152
#### [.NET Core 3.x](#tab/core3x)
151-
153+
152154
```csharp
153155
public static IHostBuilder CreateHostBuilder(string[] args) =>
154156
Host.CreateDefaultBuilder(args)
@@ -160,6 +162,7 @@ The Secret Manager tool stores sensitive data for development work outside of yo
160162
})
161163
.UseStartup<Startup>());
162164
```
165+
163166
---
164167
165168
1. Navigate to *<app root>/Views/Home* and open *Index.cshtml*. Replace its content with the following code:

articles/azure-app-configuration/quickstart-dotnet-core-app.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ You use the [.NET Core command-line interface (CLI)](https://docs.microsoft.com/
4848
1. Add a reference to the `Microsoft.Extensions.Configuration.AzureAppConfiguration` NuGet package by running the following command:
4949
5050
```CLI
51-
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration --version 3.0.0-preview-010550001-251
51+
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration --version 3.0.0-preview-011100001-1152
5252
```
5353
5454
2. Run the following command to restore packages for your project:

articles/azure-app-configuration/use-key-vault-references-dotnet-core.md

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.service: azure-app-configuration
1212
ms.workload: tbd
1313
ms.devlang: csharp
1414
ms.topic: tutorial
15-
ms.date: 10/07/2019
15+
ms.date: 01/21/2020
1616
ms.author: lcozzens
1717
ms.custom: mvc
1818

@@ -116,50 +116,102 @@ To add a secret to the vault, you need to take just a few additional steps. In t
116116
117117
1. Run the following command to let the service principal access your key vault:
118118
119-
```
119+
```cmd
120120
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
121121
```
122122
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*.
124+
125+
#### [Windows command prompt](#tab/cmd)
124126
127+
```cmd
128+
setx AZURE_CLIENT_ID <clientId-of-your-service-principal>
129+
setx AZURE_CLIENT_SECRET <clientSecret-of-your-service-principal>
130+
setx AZURE_TENANT_ID <tenantId-of-your-service-principal>
125131
```
126-
dotnet user-secrets set ConnectionStrings:KeyVaultClientId <clientId-of-your-service-principal>
127-
dotnet user-secrets set ConnectionStrings:KeyVaultClientSecret <clientSecret-of-your-service-principal>
132+
133+
#### [PowerShell](#tab/powershell)
134+
135+
```PowerShell
136+
$Env:AZURE_CLIENT_ID = <clientId-of-your-service-principal>
137+
$Env:AZURE_CLIENT_SECRET = <clientSecret-of-your-service-principal>
138+
$Env:AZURE_TENANT_ID = <tenantId-of-your-service-principal>
139+
```
140+
141+
#### [Bash](#tab/bash)
142+
143+
```bash
144+
export AZURE_CLIENT_ID = <clientId-of-your-service-principal>
145+
export AZURE_CLIENT_SECRET = <clientSecret-of-your-service-principal>
146+
export AZURE_TENANT_ID = <tenantId-of-your-service-principal>
128147
```
129148
130-
> [!NOTE]
131-
> 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.
132155
133156
## Update your code to use a Key Vault reference
134157
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+
135165
1. Open *Program.cs*, and add references to the following required packages:
136166
137167
```csharp
138168
using Microsoft.Azure.KeyVault;
139-
using Microsoft.IdentityModel.Clients.ActiveDirectory;
169+
using Azure.Identity;
140170
```
141171
142172
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.
143173
174+
#### [.NET Core 2.x](#tab/core2x)
175+
144176
```csharp
145177
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
146178
WebHost.CreateDefaultBuilder(args)
147179
.ConfigureAppConfiguration((hostingContext, config) =>
148180
{
149181
var settings = config.Build();
150182
151-
KeyVaultClient kvClient = new KeyVaultClient(async (authority, resource, scope) =>
183+
config.AddAzureAppConfiguration(options =>
152184
{
153-
var adCredential = new ClientCredential(settings["ConnectionStrings:KeyVaultClientId"], settings["ConnectionStrings:KeyVaultClientSecret"]);
154-
var authenticationContext = new AuthenticationContext(authority, null);
155-
return (await authenticationContext.AcquireTokenAsync(resource, adCredential)).AccessToken;
185+
options.Connect(settings["ConnectionStrings:AppConfig"])
186+
.ConfigureKeyVault(kv =>
187+
{
188+
kv.SetCredential(new DefaultAzureCredential());
189+
});
156190
});
191+
})
192+
.UseStartup<Startup>();
193+
```
194+
195+
#### [.NET Core 3.x](#tab/core3x)
196+
197+
```csharp
198+
public static IHostBuilder CreateHostBuilder(string[] args) =>
199+
Host.CreateDefaultBuilder(args)
200+
.ConfigureWebHostDefaults(webBuilder =>
201+
webBuilder.ConfigureAppConfiguration((hostingContext, config) =>
202+
{
203+
var settings = config.Build();
157204
158-
config.AddAzureAppConfiguration(options => {
205+
config.AddAzureAppConfiguration(options =>
206+
{
159207
options.Connect(settings["ConnectionStrings:AppConfig"])
160-
.UseAzureKeyVault(kvClient); });
208+
.ConfigureKeyVault(kv =>
209+
{
210+
kv.SetCredential(new DefaultAzureCredential());
211+
});
212+
});
161213
})
162-
.UseStartup<Startup>();
214+
.UseStartup<Startup>());
163215
```
164216
165217
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
176228
}
177229
h1 {
178230
color: @Configuration["TestApp:Settings:FontColor"];
179-
font-size: @Configuration["TestApp:Settings:FontSize"];
231+
font-size: @Configuration["TestApp:Settings:FontSize"]px;
180232
}
181233
</style>
182234

0 commit comments

Comments
 (0)