Esta página mostra os métodos de autenticação e clientes com suporte e mostra um código de exemplo que você pode usar para conectar os a Configuração de Aplicativos do Azure a outros serviços de nuvem usando o Conector de Serviço. Você ainda pode se conectar à Configuração de Aplicativos usando outros métodos. Esta página também mostra nomes e valores de variáveis de ambiente padrão que você obtém ao criar a conexão de serviço.
Serviço de computação com suporte
O Conector de Serviço pode ser usado para conectar os seguintes serviços de computação à Configuração de Aplicativos do Azure:
- Serviço de Aplicativo do Azure
- Aplicativos de Contêiner do Azure
- Azure Functions
- AKS (Serviço de Kubernetes do Azure)
- Azure Spring Apps
Tipos de autenticação e tipos de cliente com suporte
A tabela abaixo mostra quais combinações de clientes e métodos de autenticação têm suporte para conectar o serviço de computação à Configuração de Aplicativos do Azure usando o Conector de Serviço. “Sim” indica que a combinação tem suporte e “Não” indica que ela não tem.
Tipo de cliente |
Identidade gerenciada atribuída pelo sistema |
Identidade gerenciada atribuída pelo usuário |
Cadeia de conexão/segredo |
Entidade de serviço |
.NET |
Sim |
Sim |
Sim |
Sim |
Java |
Sim |
Sim |
Sim |
Sim |
Node.js |
Sim |
Sim |
Sim |
Sim |
Python |
Sim |
Sim |
Sim |
Yes |
Nenhum |
Sim |
Sim |
Sim |
Yes |
Essa tabela indica que todas as combinações de tipos de clientes e métodos de autenticação na tabela têm suporte. Todos os tipos de clientes podem usar qualquer um dos métodos de autenticação para se conectar à Configuração de Aplicativos do Azure usando o Conector de Serviço.
Nomes de variáveis de ambiente padrão ou propriedades de aplicativo e código de exemplo
Use os detalhes de conexão abaixo para conectar serviços de computação de armazenamentos da Configuração de Aplicativos do Azure. Para saber mais sobre as convenções de nomenclatura, confira o artigo Detalhes internos no conector de serviço.
Identidade gerenciada atribuída pelo sistema
Nome da variável de ambiente padrão |
Descrição |
Valor de exemplo |
AZURE_APPCONFIGURATION_ENDPOINT |
Ponto de extremidade da Configuração de Aplicativos |
https://<App-Configuration-name>.azconfig.io |
Código de exemplo
Veja as etapas e o código abaixo para se conectar à Configuração de Aplicativos do Azure usando uma identidade gerenciada atribuída pelo sistema.
Instale as dependências.
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
dotnet add package Azure.Identity
Autentique usando Azure.Identity
e obtenha o ponto de extremidade da Configuração de Aplicativos do Azure das variáveis de ambiente adicionadas pelo Conector de Serviço. Ao usar o código abaixo, descompacte a parte do snippet de código para o tipo de autenticação que você deseja usar.
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);
Adicione as dependências a seguir no seu arquivo 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>
Autentique usando azure-identity
e obtenha o ponto de extremidade da Configuração de Aplicativos do Azure das variáveis de ambiente adicionadas pelo Conector de Serviço. Ao usar o código abaixo, descompacte a parte do snippet de código para o tipo de autenticação que você deseja usar.
// 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();
- Instale as dependências.
pip install azure-appconfiguration
pip install azure-identity
- Autentique usando
azure-identity
e obtenha o ponto de extremidade da Configuração de Aplicativos do Azure das variáveis de ambiente adicionadas pelo Conector de Serviço. Ao usar o código abaixo, descompacte a parte do snippet de código para o tipo de autenticação que você deseja usar.
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)
Instale as dependências.
npm install --save @azure/identity
npm install @azure/app-configuration
Autentique usando @azure/identity
e obtenha o ponto de extremidade da Configuração de Aplicativos do Azure das variáveis de ambiente adicionadas pelo Conector de Serviço. Ao usar o código abaixo, descompacte a parte do snippet de código para o tipo de autenticação que você deseja usar.
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
);
Identidade gerenciada atribuída pelo usuário
Nome da variável de ambiente padrão |
Descrição |
Valor de exemplo |
AZURE_APPCONFIGURATION_ENDPOINT |
Ponto de extremidade da Configuração de Aplicativos |
https://App-Configuration-name>.azconfig.io |
AZURE_APPCONFIGURATION_CLIENTID |
Sua ID de cliente |
<client-ID> |
Código de exemplo
Veja as etapas e o código abaixo para se conectar à Configuração de Aplicativos do Azure usando uma identidade gerenciada atribuída pelo usuário.
Instale as dependências.
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
dotnet add package Azure.Identity
Autentique usando Azure.Identity
e obtenha o ponto de extremidade da Configuração de Aplicativos do Azure das variáveis de ambiente adicionadas pelo Conector de Serviço. Ao usar o código abaixo, descompacte a parte do snippet de código para o tipo de autenticação que você deseja usar.
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);
Adicione as dependências a seguir no seu arquivo 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>
Autentique usando azure-identity
e obtenha o ponto de extremidade da Configuração de Aplicativos do Azure das variáveis de ambiente adicionadas pelo Conector de Serviço. Ao usar o código abaixo, descompacte a parte do snippet de código para o tipo de autenticação que você deseja usar.
// 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();
- Instale as dependências.
pip install azure-appconfiguration
pip install azure-identity
- Autentique usando
azure-identity
e obtenha o ponto de extremidade da Configuração de Aplicativos do Azure das variáveis de ambiente adicionadas pelo Conector de Serviço. Ao usar o código abaixo, descompacte a parte do snippet de código para o tipo de autenticação que você deseja usar.
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)
Instale as dependências.
npm install --save @azure/identity
npm install @azure/app-configuration
Autentique usando @azure/identity
e obtenha o ponto de extremidade da Configuração de Aplicativos do Azure das variáveis de ambiente adicionadas pelo Conector de Serviço. Ao usar o código abaixo, descompacte a parte do snippet de código para o tipo de autenticação que você deseja usar.
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
);
Cadeia de conexão
Aviso
A Microsoft recomenda usar o fluxo de autenticação mais seguro disponível. O fluxo de autenticação descrito neste procedimento exige um grau muito alto de confiança no aplicativo e traz riscos que não estão presentes em outros fluxos. Você só deve usar esse fluxo quando outros fluxos mais seguros, como identidades gerenciadas, não forem viáveis.
Nome da variável de ambiente padrão |
Descrição |
Valor de exemplo |
AZURE_APPCONFIGURATION_CONNECTIONSTRING |
Sua cadeia de conexão da Configuração de Aplicativos |
Endpoint=https://<App-Configuration-name>.azconfig.io;Id=<ID>;Secret=<secret> |
Exemplo de código
Veja as etapas e o código abaixo para se conectar à Configuração de Aplicativos do Azure usando uma cadeia de conexão.
Instale as dependências.
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
Obtenha a cadeia de conexão da Configuração de Aplicativos por meio da variável de ambiente adicionada pelo Conector de Serviço.
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();
- Adicione as seguintes dependências no seu arquivo pom.xml:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-data-appconfiguration</artifactId>
<version>1.4.9</version>
</dependency>
- Obtenha a cadeia de conexão da Configuração de Aplicativos por meio da variável de ambiente adicionada pelo Conector de Serviço.
String connectionString = System.getenv("AZURE_APPCONFIGURATION_CONNECTIONSTRING");
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
.connectionString(connectionString)
.buildClient();
- Instale as dependências.
pip install azure-appconfiguration
- Obtenha a cadeia de conexão da Configuração de Aplicativos por meio da variável de ambiente adicionada pelo Conector de Serviço.
import os
from azure.appconfiguration import AzureAppConfigurationClient
connection_string = os.getenv('AZURE_APPCONFIGURATION_CONNECTIONSTRING')
app_config_client = AzureAppConfigurationClient.from_connection_string(connection_string)
Instale as dependências.
npm install @azure/app-configuration
Obtenha a cadeia de conexão da Configuração de Aplicativos por meio da variável de ambiente adicionada pelo Conector de Serviço.
const appConfig = require("@azure/app-configuration");
const connection_string = process.env.AZURE_APPCONFIGURATION_CONNECTIONSTRING;
const client = new appConfig.AppConfigurationClient(connection_string);
Entidade de serviço
Nome da variável de ambiente padrão |
Descrição |
Valor de exemplo |
AZURE_APPCONFIGURATION_ENDPOINT |
Ponto de extremidade da Configuração de Aplicativos |
https://<AppConfigurationName>.azconfig.io |
AZURE_APPCONFIGURATION_CLIENTID |
Sua ID de cliente |
<client-ID> |
AZURE_APPCONFIGURATION_CLIENTSECRET |
Seu segredo do cliente |
<client-secret> |
AZURE_APPCONFIGURATION_TENANTID |
Sua ID de locatário |
<tenant-ID> |
Código de exemplo
Veja as etapas e o código abaixo para se conectar à Configuração de Aplicativos do Azure usando uma entidade de serviço.
Instale as dependências.
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
dotnet add package Azure.Identity
Autentique usando Azure.Identity
e obtenha o ponto de extremidade da Configuração de Aplicativos do Azure das variáveis de ambiente adicionadas pelo Conector de Serviço. Ao usar o código abaixo, descompacte a parte do snippet de código para o tipo de autenticação que você deseja usar.
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);
Adicione as dependências a seguir no seu arquivo 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>
Autentique usando azure-identity
e obtenha o ponto de extremidade da Configuração de Aplicativos do Azure das variáveis de ambiente adicionadas pelo Conector de Serviço. Ao usar o código abaixo, descompacte a parte do snippet de código para o tipo de autenticação que você deseja usar.
// 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();
- Instale as dependências.
pip install azure-appconfiguration
pip install azure-identity
- Autentique usando
azure-identity
e obtenha o ponto de extremidade da Configuração de Aplicativos do Azure das variáveis de ambiente adicionadas pelo Conector de Serviço. Ao usar o código abaixo, descompacte a parte do snippet de código para o tipo de autenticação que você deseja usar.
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)
Instale as dependências.
npm install --save @azure/identity
npm install @azure/app-configuration
Autentique usando @azure/identity
e obtenha o ponto de extremidade da Configuração de Aplicativos do Azure das variáveis de ambiente adicionadas pelo Conector de Serviço. Ao usar o código abaixo, descompacte a parte do snippet de código para o tipo de autenticação que você deseja usar.
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
);
Próximas etapas
Siga os tutoriais listados abaixo para saber mais sobre o Conector de Serviço.