|
| 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). |
0 commit comments