Skip to content

Commit 632465d

Browse files
Merge pull request #255976 from wchigit/how-to-app-config
sample code of how to integrate with app configuration
2 parents 246e130 + fc04594 commit 632465d

File tree

3 files changed

+259
-34
lines changed

3 files changed

+259
-34
lines changed

articles/service-connector/how-to-integrate-app-configuration.md

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ author: maud-lv
55
ms.author: malev
66
ms.service: service-connector
77
ms.topic: how-to
8-
ms.date: 08/11/2022
8+
ms.date: 10/26/2023
99
---
1010

1111
# Integrate Azure App Configuration with Service Connector
1212

13-
This page shows the supported authentication types and client types of Azure App Configuration using Service Connector. You might still be able to connect to App Configuration in other programming languages without using Service Connector. You can learn more about the [Service Connector environment variable naming convention](concept-service-connector-internals.md).
13+
This page shows supported authentication methods and clients, and shows sample code you can use to connect Azure App Configuration to other cloud services using Service Connector. You might still be able to connect to App Configuration using other methods. For more information about naming conventions, check the [Service Connector internals](concept-service-connector-internals.md#configuration-naming-convention) article.
1414

1515
## Supported compute services
1616

@@ -22,18 +22,6 @@ This page shows the supported authentication types and client types of Azure App
2222

2323
Supported authentication and clients for App Service, Container Apps and Azure Spring Apps:
2424

25-
### [Azure App Service](#tab/app-service)
26-
27-
| Client type | System-assigned managed identity | User-assigned managed identity | Secret/connection string | Service principal |
28-
|-------------|:------------------------------------:|:------------------------------------:|:------------------------------------:|:------------------------------------:|
29-
| .NET | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
30-
| Java | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
31-
| Node.js | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
32-
| Python | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
33-
| None | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
34-
35-
### [Azure Container Apps](#tab/container-apps)
36-
3725
| Client type | System-assigned managed identity | User-assigned managed identity | Secret/connection string | Service principal |
3826
|-------------|:------------------------------------:|:------------------------------------:|:------------------------------------:|:------------------------------------:|
3927
| .NET | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
@@ -42,43 +30,43 @@ Supported authentication and clients for App Service, Container Apps and Azure S
4230
| Python | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
4331
| None | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
4432

45-
### [Azure Spring Apps](#tab/spring-apps)
46-
47-
| Client type | System-assigned managed identity | User-assigned managed identity | Secret/connection string | Service principal |
48-
|-------------|:------------------------------------:|:------------------------------------:|:------------------------------------:|:------------------------------------:|
49-
| .NET | ![yes icon](./media/green-check.png) | | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
50-
| Java | ![yes icon](./media/green-check.png) | | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
51-
| Node.js | ![yes icon](./media/green-check.png) | | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
52-
| Python | ![yes icon](./media/green-check.png) | | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
53-
| None | ![yes icon](./media/green-check.png) | | ![yes icon](./media/green-check.png) | ![yes icon](./media/green-check.png) |
54-
5533
---
5634

57-
## Default environment variable names or application properties
35+
## Default environment variable names or application properties and sample code
5836

59-
Use the connection details below to connect compute services to Azure App Configuration stores instances. For each example below, replace the placeholder texts
60-
`<App-Configuration-name>`, `<ID>`, `<secret>`, `<client-ID>`, `<client-secret>`, and `<tenant-ID>` with your App Configuration store name, ID, secret, client ID, client secret and tenant ID.
61-
62-
### Secret / connection string
63-
64-
> [!div class="mx-tdBreakAll"]
65-
> | Default environment variable name | Description | Sample value |
66-
> | --------------------------------- | ------------| ------------ |
67-
> | AZURE_APPCONFIGURATION_CONNECTIONSTRING | Your App Configuration Connection String | `Endpoint=https://<App-Configuration-name>.azconfig.io;Id=<ID>;Secret=<secret>` |
37+
Use the connection details below to connect compute services to Azure App Configuration stores. This page also shows default environment variable names and values you get when you create the service connection, as well as sample code. For more information about naming conventions, check the [Service Connector internals](concept-service-connector-internals.md#configuration-naming-convention) article.
6838

6939
### System-assigned managed identity
7040

7141
| Default environment variable name | Description | Sample value |
7242
|-----------------------------------|------------------------------|------------------------------------------------|
7343
| AZURE_APPCONFIGURATION_ENDPOINT | App Configuration endpoint | `https://<App-Configuration-name>.azconfig.io` |
7444

45+
Refer to the steps and code below to connect to Azure App Configuration using a system-assigned managed identity.
46+
[!INCLUDE [code sample for app config](./includes/code-appconfig-me-id.md)]
47+
7548
### User-assigned managed identity
7649

7750
| Default environment variable name | Description | Sample value |
7851
|-----------------------------------|----------------------------|-----------------------------------------------|
7952
| AZURE_APPCONFIGURATION_ENDPOINT | App Configuration Endpoint | `https://App-Configuration-name>.azconfig.io` |
8053
| AZURE_APPCONFIGURATION_CLIENTID | Your client ID | `<client-ID>` |
8154

55+
Refer to the steps and code below to connect to Azure App Configuration using a user-assigned managed identity.
56+
[!INCLUDE [code sample for app config](./includes/code-appconfig-me-id.md)]
57+
58+
### Connection string
59+
60+
> [!div class="mx-tdBreakAll"]
61+
> | Default environment variable name | Description | Sample value |
62+
> | --------------------------------- | ------------| ------------ |
63+
> | AZURE_APPCONFIGURATION_CONNECTIONSTRING | Your App Configuration Connection String | `Endpoint=https://<App-Configuration-name>.azconfig.io;Id=<ID>;Secret=<secret>` |
64+
65+
#### Sample Code
66+
Refer to the steps and code below to connect to Azure App Configuration using a connection string.
67+
[!INCLUDE [code sample for app config](./includes/code-appconfig-secret.md)]
68+
69+
8270
### Service principal
8371

8472
| Default environment variable name | Description | Sample value |
@@ -88,6 +76,9 @@ Use the connection details below to connect compute services to Azure App Config
8876
| AZURE_APPCONFIGURATION_CLIENTSECRET | Your client secret | `<client-secret>` |
8977
| AZURE_APPCONFIGURATION_TENANTID | Your tenant ID | `<tenant-ID>` |
9078

79+
Refer to the steps and code below to connect to Azure App Configuration using a service principaL.
80+
[!INCLUDE [code sample for app config](./includes/code-appconfig-me-id.md)]
81+
9182
## Next steps
9283

9384
Follow the tutorial listed below to learn more about Service Connector.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
---
2+
author: wchigit
3+
ms.service: service-connector
4+
ms.topic: include
5+
ms.date: 10/20/2023
6+
ms.author: wchi
7+
---
8+
9+
### [.NET](#tab/dotnet)
10+
11+
1. Install dependencies.
12+
```bash
13+
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
14+
dotnet add package Azure.Identity
15+
```
16+
1. Authenticate using `Azure.Identity` and get the Azure App Configuration endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
17+
18+
```csharp
19+
using Azure.Identity;
20+
using Microsoft.Extensions.Configuration;
21+
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
22+
23+
string endpoint = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_ENDPOINT");
24+
25+
// Uncomment the following lines according to the authentication type.
26+
// system-assigned managed identity
27+
// var credential = new DefaultAzureCredential();
28+
29+
// user-assigned managed identity
30+
// var credential = new DefaultAzureCredential(
31+
// new DefaultAzureCredentialOptions
32+
// {
33+
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
34+
// });
35+
36+
// service principal
37+
// var tenantId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_TENANTID");
38+
// var clientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
39+
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTSECRET");
40+
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
41+
42+
var client = new ConfigurationClient(new Uri(endpoint), credential);
43+
```
44+
45+
### [Java](#tab/java)
46+
47+
1. Add the following dependencies in your *pom.xml* file:
48+
```xml
49+
<dependency>
50+
<groupId>com.azure</groupId>
51+
<artifactId>azure-data-appconfiguration</artifactId>
52+
<version>1.4.9</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>com.azure</groupId>
56+
<artifactId>azure-identity</artifactId>
57+
<version>1.1.5</version>
58+
</dependency>
59+
```
60+
1. Authenticate using `azure-identity` and get the Azure App Configuration endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
61+
62+
```java
63+
// Uncomment the following lines according to the authentication type.
64+
// for system-managed identity
65+
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
66+
67+
// for user-assigned managed identity
68+
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
69+
// .managedIdentityClientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
70+
// .build();
71+
72+
// for service principal
73+
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
74+
// .clientId(System.getenv("<AZURE_APPCONFIGURATION_CLIENTID>"))
75+
// .clientSecret(System.getenv("<AZURE_APPCONFIGURATION_CLIENTSECRET>"))
76+
// .tenantId(System.getenv("<AZURE_APPCONFIGURATION_TENANTID>"))
77+
// .build();
78+
79+
String endpoint = System.getenv("AZURE_APPCONFIGURATION_ENDPOINT");
80+
81+
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
82+
.credential(credential)
83+
.endpoint(endpoint)
84+
.buildClient();
85+
```
86+
87+
### [Python](#tab/python)
88+
89+
1. Install dependencies.
90+
```bash
91+
pip install azure-appconfiguration
92+
pip install azure-identity
93+
```
94+
1. Authenticate using `azure-identity` and get the Azure App Configuration endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
95+
```python
96+
import os
97+
from azure.appconfiguration import AzureAppConfigurationClient
98+
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
99+
100+
# Uncomment the following lines according to the authentication type.
101+
# system-assigned managed identity
102+
# cred = ManagedIdentityCredential()
103+
104+
# user-assigned managed identity
105+
# managed_identity_client_id = os.getenv('AZURE_APPCONFIGURATION_CLIENTID')
106+
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
107+
108+
# service principal
109+
# tenant_id = os.getenv('AZURE_APPCONFIGURATION_TENANTID')
110+
# client_id = os.getenv('AZURE_APPCONFIGURATION_CLIENTID')
111+
# client_secret = os.getenv('AZURE_APPCONFIGURATION_CLIENTSECRET')
112+
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
113+
114+
endpoint_url = os.getenv('AZURE_APPCONFIGURATION_ENDPOINT')
115+
116+
client = AzureAppConfigurationClient(base_url="your_endpoint_url", credential=credential)
117+
```
118+
119+
### [NodeJS](#tab/nodejs)
120+
121+
1. Install dependencies.
122+
```bash
123+
npm install --save @azure/identity
124+
npm install @azure/app-configuration
125+
```
126+
1. Authenticate using `@azure/identity` and get the Azure App Configuration endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
127+
128+
```javascript
129+
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
130+
const appConfig = require("@azure/app-configuration");
131+
132+
// Uncomment the following lines according to the authentication type.
133+
// for system-assigned managed identity
134+
// const credential = new DefaultAzureCredential();
135+
136+
// for user-assigned managed identity
137+
// const clientId = process.env.AZURE_APPCONFIGURATION_CLIENTID;
138+
// const credential = new DefaultAzureCredential({
139+
// managedIdentityClientId: clientId
140+
// });
141+
142+
// for service principal
143+
// const tenantId = process.env.AZURE_APPCONFIGURATION_TENANTID;
144+
// const clientId = process.env.AZURE_APPCONFIGURATION_CLIENTID;
145+
// const clientSecret = process.env.AZURE_APPCONFIGURATION_CLIENTSECRET;
146+
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
147+
148+
const endpoint = process.env.AZURE_APPCONFIGURATION_ENDPOINT;
149+
150+
const client = new appConfig.AppConfigurationClient(
151+
endpoint,
152+
credential
153+
);
154+
```
155+
156+
### [Other](#tab/other)
157+
For other languages, you can use the connection information that Service Connector set to the environment variables to connect Azure App Configuration. For environment variable details, see [Integrate Azure App Configuration with Service Connector](../how-to-integrate-app-configuration.md).
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
author: wchigit
3+
ms.service: service-connector
4+
ms.topic: include
5+
ms.date: 10/24/2023
6+
ms.author: wchi
7+
---
8+
9+
### [.NET](#tab/dotnet)
10+
11+
1. Install dependencies.
12+
```bash
13+
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
14+
```
15+
1. Get the App Configuration connection string from the environment variables added by Service Connector.
16+
17+
```csharp
18+
using Microsoft.Extensions.Configuration;
19+
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
20+
21+
var connectionString = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CONNECTIONSTRING");
22+
var builder = new ConfigurationBuilder();
23+
builder.AddAzureAppConfiguration(connectionString);
24+
25+
var config = builder.Build();
26+
```
27+
28+
### [Java](#tab/java)
29+
30+
1. Add the following dependencies in your *pom.xml* file:
31+
```xml
32+
<dependency>
33+
<groupId>com.azure</groupId>
34+
<artifactId>azure-data-appconfiguration</artifactId>
35+
<version>1.4.9</version>
36+
</dependency>
37+
```
38+
1. Get the App Configuration connection string from the environment variables added by Service Connector.
39+
```java
40+
String connectionString = System.getenv("AZURE_APPCONFIGURATION_CONNECTIONSTRING");
41+
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
42+
.connectionString(connectionString)
43+
.buildClient();
44+
```
45+
46+
### [Python](#tab/python)
47+
48+
1. Install dependencies.
49+
```bash
50+
pip install azure-appconfiguration
51+
```
52+
1. Get the App Configuration connection string from the environment variables added by Service Connector.
53+
```python
54+
import os
55+
from azure.appconfiguration import AzureAppConfigurationClient
56+
57+
connection_string = os.getenv('AZURE_APPCONFIGURATION_CONNECTIONSTRING')
58+
app_config_client = AzureAppConfigurationClient.from_connection_string(connection_string)
59+
```
60+
61+
### [NodeJS](#tab/nodejs)
62+
63+
1. Install dependencies.
64+
```bash
65+
npm install @azure/app-configuration
66+
```
67+
1. Get the App Configuration connection string from the environment variables added by Service Connector.
68+
69+
```javascript
70+
const appConfig = require("@azure/app-configuration");
71+
72+
const connection_string = process.env.AZURE_APPCONFIGURATION_CONNECTIONSTRING;
73+
const client = new appConfig.AppConfigurationClient(connection_string);
74+
```
75+
76+
### [Other](#tab/other)
77+
For other languages, you can use the connection information that Service Connector set to the environment variables to connect Azure App Configuration. For environment variable details, see [Integrate Azure App Configuration with Service Connector](../how-to-integrate-app-configuration.md).

0 commit comments

Comments
 (0)