Skip to content

Commit 1f49efe

Browse files
add AAD for js doc
1 parent 354e7b7 commit 1f49efe

File tree

3 files changed

+239
-81
lines changed

3 files changed

+239
-81
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-javascript.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ title: Use dynamic configuration in JavaScript
33
titleSuffix: Azure App Configuration
44
description: Learn how to dynamically update configuration data for JavaScript.
55
services: azure-app-configuration
6-
author: eskibear
6+
author: zhiyuanliang-ms
77
ms.service: azure-app-configuration
88
ms.devlang: javascript
99
ms.topic: tutorial
1010
ms.date: 03/27/2024
1111
ms.custom: devx-track-js
12-
ms.author: yanzh
12+
ms.author: zhiyuanliang
1313
#Customer intent: As a JavaScript developer, I want to dynamically update my app to use the latest configuration data in Azure App Configuration.
1414
---
1515
# Tutorial: Use dynamic configuration in JavaScript
@@ -44,8 +44,8 @@ Choose the following instructions based on how your application consumes configu
4444
### [Use configuration as Map](#tab/configuration-map)
4545

4646
```javascript
47-
// Connecting to Azure App Configuration using connection string
48-
const settings = await load(connectionString, {
47+
// Connecting to Azure App Configuration using endpoint and token credential
48+
const settings = await load(endpoint, credential, {
4949
// Setting up to refresh when the sentinel key is changed
5050
refreshOptions: {
5151
enabled: true,
@@ -60,8 +60,8 @@ Choose the following instructions based on how your application consumes configu
6060
To ensure an up-to-date configuration, update the configuration object in the `onRefresh` callback triggered whenever a configuration change is detected and the configuration is updated.
6161

6262
```javascript
63-
// Connecting to Azure App Configuration using connection string
64-
const settings = await load(connectionString, {
63+
// Connecting to Azure App Configuration using endpoint and token credential
64+
const settings = await load(endpoint, credential, {
6565
// Setting up to refresh when the sentinel key is changed
6666
refreshOptions: {
6767
enabled: true,
@@ -115,11 +115,13 @@ Choose the following instructions based on how your application consumes configu
115115
```javascript
116116
const sleepInMs = require("util").promisify(setTimeout);
117117
const { load } = require("@azure/app-configuration-provider");
118-
const connectionString = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
118+
const { DefaultAzureCredential } = require("@azure/identity");
119+
const endpoint = process.env.AZURE_APPCONFIG_ENDPOINT;
120+
const credential = new DefaultAzureCredential(); // For more information, see https://learn.microsoft.com/azure/developer/javascript/sdk/credential-chains#use-defaultazurecredential-for-flexibility
119121
120122
async function run() {
121-
// Connecting to Azure App Configuration using connection string
122-
const settings = await load(connectionString, {
123+
// Connecting to Azure App Configuration using endpoint and token credential
124+
const settings = await load(endpoint, credential, {
123125
// Setting up to refresh when the sentinel key is changed
124126
refreshOptions: {
125127
enabled: true,
@@ -142,11 +144,13 @@ Choose the following instructions based on how your application consumes configu
142144
```javascript
143145
const sleepInMs = require("util").promisify(setTimeout);
144146
const { load } = require("@azure/app-configuration-provider");
145-
const connectionString = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
147+
const { DefaultAzureCredential } = require("@azure/identity");
148+
const endpoint = process.env.AZURE_APPCONFIG_ENDPOINT;
149+
const credential = new DefaultAzureCredential(); // For more information, see https://learn.microsoft.com/azure/developer/javascript/sdk/credential-chains#use-defaultazurecredential-for-flexibility
146150
147151
async function run() {
148-
// Connecting to Azure App Configuration using connection string
149-
const settings = await load(connectionString, {
152+
// Connecting to Azure App Configuration using endpoint and token credential
153+
const settings = await load(endpoint, credential, {
150154
// Setting up to refresh when the sentinel key is changed
151155
refreshOptions: {
152156
enabled: true,

articles/azure-app-configuration/quickstart-feature-flag-javascript.md

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,54 @@ Add a feature flag called *Beta* to the App Configuration store and leave **Labe
4242

4343
1. Create a file named *app.js* and add the following code.
4444

45+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
46+
You use the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role. Be sure to allow sufficient time for the permission to propagate before running your application.
47+
4548
``` javascript
4649
const sleepInMs = require("util").promisify(setTimeout);
4750
const { load } = require("@azure/app-configuration-provider");
48-
const { FeatureManager, ConfigurationMapFeatureFlagProvider} = require("@microsoft/feature-management")
51+
const { DefaultAzureCredential } = require("@azure/identity");
52+
const { FeatureManager, ConfigurationMapFeatureFlagProvider} = require("@microsoft/feature-management");
53+
const endpoint = process.env.AZURE_APPCONFIG_ENDPOINT;
54+
const credential = new DefaultAzureCredential(); // For more information, see https://learn.microsoft.com/azure/developer/javascript/sdk/credential-chains#use-defaultazurecredential-for-flexibility
55+
56+
async function run() {
57+
// Connect to Azure App Configuration using connection string
58+
const settings = await load(connectionString, {
59+
featureFlagOptions: {
60+
enabled: true,
61+
// Note: selectors must be explicitly provided for feature flags.
62+
selectors: [{
63+
keyFilter: "*"
64+
}],
65+
refresh: {
66+
enabled: true,
67+
refreshIntervalInMs: 10_000
68+
}
69+
}
70+
});
71+
72+
// Create a feature flag provider which uses a map as feature flag source
73+
const ffProvider = new ConfigurationMapFeatureFlagProvider(settings);
74+
// Create a feature manager which will evaluate the feature flag
75+
const fm = new FeatureManager(ffProvider);
76+
77+
while (true) {
78+
await settings.refresh(); // Refresh to get the latest feature flag settings
79+
const isEnabled = await fm.isEnabled("Beta"); // Evaluate the feature flag
80+
console.log(`Beta is enabled: ${isEnabled}`);
81+
await sleepInMs(5000);
82+
}
83+
}
84+
85+
run().catch(console.error);
86+
```
87+
88+
### [Connection string](#tab/connection-string)
89+
``` javascript
90+
const sleepInMs = require("util").promisify(setTimeout);
91+
const { load } = require("@azure/app-configuration-provider");
92+
const { FeatureManager, ConfigurationMapFeatureFlagProvider} = require("@microsoft/feature-management");
4993
const connectionString = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
5094

5195
async function run() {
@@ -80,42 +124,54 @@ Add a feature flag called *Beta* to the App Configuration store and leave **Labe
80124
run().catch(console.error);
81125
```
82126

127+
---
128+
83129
## Run the application
84130

85-
1. Set an environment variable named **AZURE_APPCONFIG_CONNECTION_STRING**, and set it to the connection string of your App Configuration store. At the command line, run the following command:
131+
1. Set the environment variable.
86132

87-
### [Windows command prompt](#tab/windowscommandprompt)
133+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
134+
Set the environment variable named **AZURE_APPCONFIG_ENDPOINT** to the endpoint of your App Configuration store found under the *Overview* of your store in the Azure portal.
88135

89-
To run the app locally using the Windows command prompt, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
136+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
90137

91138
```cmd
92-
setx AZURE_APPCONFIG_CONNECTION_STRING "<app-configuration-store-connection-string>"
139+
setx AZURE_APPCONFIG_ENDPOINT "endpoint-of-your-app-configuration-store"
93140
```
94141

95-
### [PowerShell](#tab/powershell)
142+
If you use PowerShell, run the following command:
96143

97-
If you use Windows PowerShell, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
144+
```powershell
145+
$Env:AZURE_APPCONFIG_ENDPOINT = "endpoint-of-your-app-configuration-store"
146+
```
98147

99-
```azurepowershell
100-
$Env:AZURE_APPCONFIG_CONNECTION_STRING = "<app-configuration-store-connection-string>"
148+
If you use macOS or Linux, run the following command:
149+
150+
```bash
151+
export AZURE_APPCONFIG_ENDPOINT='endpoint-of-your-app-configuration-store'
101152
```
102153

103-
### [macOS](#tab/unix)
154+
### [Connection string](#tab/connection-string)
155+
Set the environment variable named **AZURE_APPCONFIG_CONNECTION_STRING** to the read-only connection string of your App Configuration store found under *Access keys* of your store in the Azure portal.
104156

105-
If you use macOS, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
157+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
106158

107-
```console
108-
export AZURE_APPCONFIG_CONNECTION_STRING='<app-configuration-store-connection-string>'
159+
```cmd
160+
setx AZURE_APPCONFIG_CONNECTION_STRING "connection-string-of-your-app-configuration-store"
109161
```
110162

111-
### [Linux](#tab/linux)
112-
113-
If you use Linux, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
163+
If you use PowerShell, run the following command:
114164

115-
```console
116-
export AZURE_APPCONFIG_CONNECTION_STRING='<app-configuration-store-connection-string>'
165+
```powershell
166+
$Env:AZURE_APPCONFIG_CONNECTION_STRING = "connection-string-of-your-app-configuration-store"
117167
```
118168

169+
If you use macOS or Linux, run the following command:
170+
171+
```bash
172+
export AZURE_APPCONFIG_CONNECTION_STRING='connection-string-of-your-app-configuration-store'
173+
```
174+
119175
---
120176

121177
1. Run the following command to run the app locally:

0 commit comments

Comments
 (0)