此頁面會顯示支援的驗證方法和用戶端,並顯示範例程式碼,您可以用來將 Azure 應用程式組態連線到使用服務連接器的其他雲端服務。 您可能仍可以使用其他方法連線到應用程式組態。 此頁面也顯示您在建立服務連線時取得的預設環境變數名稱和值。
支援的計算服務
服務連接器可用來將下列計算服務連線至 Azure 應用程式組態:
- Azure App Service
- Azure 容器應用程式
- Azure Functions
- Azure Kubernetes Service (AKS)
- Azure Spring Apps
支援的驗證類型和用戶端類型
下表顯示使用服務連接器將計算服務連線到 Azure 應用程式組態時,支援哪些驗證方法和用戶端組合。 「是」表示支援的組合,而「否」則表示不支援。
用戶端類型 |
系統指派的受控識別 |
使用者指派的受控識別 |
祕密/連接字串 |
服務主體 |
.NET |
Yes |
.是 |
.是 |
Yes |
Java |
Yes |
.是 |
.是 |
Yes |
Node.js |
Yes |
.是 |
.是 |
Yes |
Python |
Yes |
.是 |
.是 |
Yes |
無 |
Yes |
.是 |
.是 |
Yes |
下表指出支源表格中所有用戶端類型和驗證方法組合。 所有用戶端類型都可以使用任何驗證方法,使用服務連接器連線到 Azure 應用程式組態。
預設環境變數名稱或應用程式屬性和範例程式碼
使用下列連線詳細資料,將計算服務連線到 Azure 應用程式組態存放區。 如需命名慣例的詳細資訊,請參閱服務連接器內部一文。
系統指派的受控識別
預設環境變數名稱 |
描述 |
範例值 |
AZURE_APPCONFIGURATION_ENDPOINT |
應用程式組態端點 |
https://<App-Configuration-name>.azconfig.io |
範例指令碼
請參閱下面的步驟和程式碼,以使用系統指派的受控識別來連線到 Azure 應用程式組態。
安裝相依性。
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
dotnet add package Azure.Identity
使用 Azure.Identity
進行驗證,並從服務連接器新增的環境變數中取得 Azure 應用程式組態端點。 使用下列程式代碼時,請取消註解您想要使用的驗證類型代碼段部分。
using Azure.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
string endpoint = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_ENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var client = new ConfigurationClient(new Uri(endpoint), credential);
在您的 pom.xml 中新增下列相依性:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-data-appconfiguration</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.1.5</version>
</dependency>
使用 azure-identity
進行驗證,並從服務連接器新增的環境變數中取得 Azure 應用程式組態端點。 使用下列程式代碼時,請取消註解您想要使用的驗證類型代碼段部分。
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
// for user-assigned managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
// .clientSecret(System.getenv("AZURE_APPCONFIGURATION_CLIENTSECRET"))
// .tenantId(System.getenv("AZURE_APPCONFIGURATION_TENANTID"))
// .build();
String endpoint = System.getenv("AZURE_APPCONFIGURATION_ENDPOINT");
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
.credential(credential)
.endpoint(endpoint)
.buildClient();
- 安裝相依性。
pip install azure-appconfiguration
pip install azure-identity
- 使用
azure-identity
進行驗證,並從服務連接器新增的環境變數中取得 Azure 應用程式組態端點。 使用下列程式代碼時,請取消註解您想要使用的驗證類型代碼段部分。
import os
from azure.appconfiguration import AzureAppConfigurationClient
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
# Uncomment the following lines corresponding to the authentication type you want to use.
# system-assigned managed identity
# cred = ManagedIdentityCredential()
# user-assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_APPCONFIGURATION_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_APPCONFIGURATION_TENANTID')
# client_id = os.getenv('AZURE_APPCONFIGURATION_CLIENTID')
# client_secret = os.getenv('AZURE_APPCONFIGURATION_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
endpoint_url = os.getenv('AZURE_APPCONFIGURATION_ENDPOINT')
client = AzureAppConfigurationClient(base_url="your_endpoint_url", credential=credential)
安裝相依性。
npm install --save @azure/identity
npm install @azure/app-configuration
使用 @azure/identity
進行驗證,並從服務連接器新增的環境變數中取得 Azure 應用程式組態端點。 使用下列程式代碼時,請取消註解您想要使用的驗證類型代碼段部分。
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
const appConfig = require("@azure/app-configuration");
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-assigned managed identity
// const credential = new DefaultAzureCredential();
// for user-assigned managed identity
// const clientId = process.env.AZURE_APPCONFIGURATION_CLIENTID;
// const credential = new DefaultAzureCredential({
// managedIdentityClientId: clientId
// });
// for service principal
// const tenantId = process.env.AZURE_APPCONFIGURATION_TENANTID;
// const clientId = process.env.AZURE_APPCONFIGURATION_CLIENTID;
// const clientSecret = process.env.AZURE_APPCONFIGURATION_CLIENTSECRET;
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const endpoint = process.env.AZURE_APPCONFIGURATION_ENDPOINT;
const client = new appConfig.AppConfigurationClient(
endpoint,
credential
);
使用者指派的受控識別
預設環境變數名稱 |
描述 |
範例值 |
AZURE_APPCONFIGURATION_ENDPOINT |
應用程式組態端點 |
https://App-Configuration-name>.azconfig.io |
AZURE_APPCONFIGURATION_CLIENTID |
您的用戶端識別碼 |
<client-ID> |
範例指令碼
請參閱下面的步驟和程式碼,透過使用者指派的受控識別,以連線到 Azure 應用程式組態。
安裝相依性。
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
dotnet add package Azure.Identity
使用 Azure.Identity
進行驗證,並從服務連接器新增的環境變數中取得 Azure 應用程式組態端點。 使用下列程式代碼時,請取消註解您想要使用的驗證類型代碼段部分。
using Azure.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
string endpoint = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_ENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var client = new ConfigurationClient(new Uri(endpoint), credential);
在您的 pom.xml 中新增下列相依性:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-data-appconfiguration</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.1.5</version>
</dependency>
使用 azure-identity
進行驗證,並從服務連接器新增的環境變數中取得 Azure 應用程式組態端點。 使用下列程式代碼時,請取消註解您想要使用的驗證類型代碼段部分。
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
// for user-assigned managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
// .clientSecret(System.getenv("AZURE_APPCONFIGURATION_CLIENTSECRET"))
// .tenantId(System.getenv("AZURE_APPCONFIGURATION_TENANTID"))
// .build();
String endpoint = System.getenv("AZURE_APPCONFIGURATION_ENDPOINT");
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
.credential(credential)
.endpoint(endpoint)
.buildClient();
- 安裝相依性。
pip install azure-appconfiguration
pip install azure-identity
- 使用
azure-identity
進行驗證,並從服務連接器新增的環境變數中取得 Azure 應用程式組態端點。 使用下列程式代碼時,請取消註解您想要使用的驗證類型代碼段部分。
import os
from azure.appconfiguration import AzureAppConfigurationClient
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
# Uncomment the following lines corresponding to the authentication type you want to use.
# system-assigned managed identity
# cred = ManagedIdentityCredential()
# user-assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_APPCONFIGURATION_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_APPCONFIGURATION_TENANTID')
# client_id = os.getenv('AZURE_APPCONFIGURATION_CLIENTID')
# client_secret = os.getenv('AZURE_APPCONFIGURATION_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
endpoint_url = os.getenv('AZURE_APPCONFIGURATION_ENDPOINT')
client = AzureAppConfigurationClient(base_url="your_endpoint_url", credential=credential)
安裝相依性。
npm install --save @azure/identity
npm install @azure/app-configuration
使用 @azure/identity
進行驗證,並從服務連接器新增的環境變數中取得 Azure 應用程式組態端點。 使用下列程式代碼時,請取消註解您想要使用的驗證類型代碼段部分。
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
const appConfig = require("@azure/app-configuration");
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-assigned managed identity
// const credential = new DefaultAzureCredential();
// for user-assigned managed identity
// const clientId = process.env.AZURE_APPCONFIGURATION_CLIENTID;
// const credential = new DefaultAzureCredential({
// managedIdentityClientId: clientId
// });
// for service principal
// const tenantId = process.env.AZURE_APPCONFIGURATION_TENANTID;
// const clientId = process.env.AZURE_APPCONFIGURATION_CLIENTID;
// const clientSecret = process.env.AZURE_APPCONFIGURATION_CLIENTSECRET;
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const endpoint = process.env.AZURE_APPCONFIGURATION_ENDPOINT;
const client = new appConfig.AppConfigurationClient(
endpoint,
credential
);
Connection string
警告
Microsoft 建議您使用最安全的可用驗證流程。 這個程序描述的驗證流程需要在應用程式中具備極高的信任度,且伴隨著其他流程並未面臨的風險。 請僅在其他較安全的流程 (例如受控身分識別) 皆不具可行性的情況下,才使用這個流程。
預設環境變數名稱 |
描述 |
範例值 |
AZURE_APPCONFIGURATION_CONNECTIONSTRING |
您的應用程式組態連接字串 |
Endpoint=https://<App-Configuration-name>.azconfig.io;Id=<ID>;Secret=<secret> |
範例程式碼
請參閱下面的步驟和程式碼,以使用連接字串來連線到 Azure 應用程式組態。
安裝相依性。
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
從服務連接器新增的環境變數取得應用程式組態連接字串。
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
var connectionString = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CONNECTIONSTRING");
var builder = new ConfigurationBuilder();
builder.AddAzureAppConfiguration(connectionString);
var config = builder.Build();
- 在您的 pom.xml 中新增下列相依性:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-data-appconfiguration</artifactId>
<version>1.4.9</version>
</dependency>
- 從服務連接器新增的環境變數取得應用程式組態連接字串。
String connectionString = System.getenv("AZURE_APPCONFIGURATION_CONNECTIONSTRING");
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
.connectionString(connectionString)
.buildClient();
- 安裝相依性。
pip install azure-appconfiguration
- 從服務連接器新增的環境變數取得應用程式組態連接字串。
import os
from azure.appconfiguration import AzureAppConfigurationClient
connection_string = os.getenv('AZURE_APPCONFIGURATION_CONNECTIONSTRING')
app_config_client = AzureAppConfigurationClient.from_connection_string(connection_string)
安裝相依性。
npm install @azure/app-configuration
從服務連接器新增的環境變數取得應用程式組態連接字串。
const appConfig = require("@azure/app-configuration");
const connection_string = process.env.AZURE_APPCONFIGURATION_CONNECTIONSTRING;
const client = new appConfig.AppConfigurationClient(connection_string);
服務主體
預設環境變數名稱 |
描述 |
範例值 |
AZURE_APPCONFIGURATION_ENDPOINT |
應用程式組態端點 |
https://<AppConfigurationName>.azconfig.io |
AZURE_APPCONFIGURATION_CLIENTID |
您的用戶端識別碼 |
<client-ID> |
AZURE_APPCONFIGURATION_CLIENTSECRET |
您的用戶端密碼 |
<client-secret> |
AZURE_APPCONFIGURATION_TENANTID |
您的租用戶識別碼 |
<tenant-ID> |
範例指令碼
請參閱下面的步驟和程式碼,以使用服務主體來連線到 Azure 應用程式組態。
安裝相依性。
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
dotnet add package Azure.Identity
使用 Azure.Identity
進行驗證,並從服務連接器新增的環境變數中取得 Azure 應用程式組態端點。 使用下列程式代碼時,請取消註解您想要使用的驗證類型代碼段部分。
using Azure.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
string endpoint = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_ENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var client = new ConfigurationClient(new Uri(endpoint), credential);
在您的 pom.xml 中新增下列相依性:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-data-appconfiguration</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.1.5</version>
</dependency>
使用 azure-identity
進行驗證,並從服務連接器新增的環境變數中取得 Azure 應用程式組態端點。 使用下列程式代碼時,請取消註解您想要使用的驗證類型代碼段部分。
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
// for user-assigned managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
// .clientSecret(System.getenv("AZURE_APPCONFIGURATION_CLIENTSECRET"))
// .tenantId(System.getenv("AZURE_APPCONFIGURATION_TENANTID"))
// .build();
String endpoint = System.getenv("AZURE_APPCONFIGURATION_ENDPOINT");
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
.credential(credential)
.endpoint(endpoint)
.buildClient();
- 安裝相依性。
pip install azure-appconfiguration
pip install azure-identity
- 使用
azure-identity
進行驗證,並從服務連接器新增的環境變數中取得 Azure 應用程式組態端點。 使用下列程式代碼時,請取消註解您想要使用的驗證類型代碼段部分。
import os
from azure.appconfiguration import AzureAppConfigurationClient
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
# Uncomment the following lines corresponding to the authentication type you want to use.
# system-assigned managed identity
# cred = ManagedIdentityCredential()
# user-assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_APPCONFIGURATION_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_APPCONFIGURATION_TENANTID')
# client_id = os.getenv('AZURE_APPCONFIGURATION_CLIENTID')
# client_secret = os.getenv('AZURE_APPCONFIGURATION_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
endpoint_url = os.getenv('AZURE_APPCONFIGURATION_ENDPOINT')
client = AzureAppConfigurationClient(base_url="your_endpoint_url", credential=credential)
安裝相依性。
npm install --save @azure/identity
npm install @azure/app-configuration
使用 @azure/identity
進行驗證,並從服務連接器新增的環境變數中取得 Azure 應用程式組態端點。 使用下列程式代碼時,請取消註解您想要使用的驗證類型代碼段部分。
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
const appConfig = require("@azure/app-configuration");
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-assigned managed identity
// const credential = new DefaultAzureCredential();
// for user-assigned managed identity
// const clientId = process.env.AZURE_APPCONFIGURATION_CLIENTID;
// const credential = new DefaultAzureCredential({
// managedIdentityClientId: clientId
// });
// for service principal
// const tenantId = process.env.AZURE_APPCONFIGURATION_TENANTID;
// const clientId = process.env.AZURE_APPCONFIGURATION_CLIENTID;
// const clientSecret = process.env.AZURE_APPCONFIGURATION_CLIENTSECRET;
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const endpoint = process.env.AZURE_APPCONFIGURATION_ENDPOINT;
const client = new appConfig.AppConfigurationClient(
endpoint,
credential
);
下一步
請透過下方列出的教學課程深入了解服務連接器。