Skip to content

Commit 5fc3bdb

Browse files
committed
Draft adding Entra ID to quickstart Javascript
1 parent cd1fa5b commit 5fc3bdb

File tree

1 file changed

+150
-53
lines changed

1 file changed

+150
-53
lines changed

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

Lines changed: 150 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.service: azure-app-configuration
77
ms.devlang: javascript
88
ms.topic: sample
99
ms.custom: mode-other, devx-track-js
10-
ms.date: 03/20/2023
10+
ms.date: 02/20/2025
1111
ms.author: malev
1212
#Customer intent: As a JavaScript developer, I want to manage all my app settings in one place.
1313
---
@@ -68,75 +68,91 @@ Add the following key-value to the App Configuration store and leave **Label** a
6868
> [!NOTE]
6969
> The code snippets in this example will help you get started with the App Configuration client library for JavaScript. For your application, you should also consider handling exceptions according to your needs. To learn more about exception handling, please refer to our [JavaScript SDK documentation](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/appconfiguration/app-configuration).
7070

71-
## Configure your App Configuration connection string
71+
## Configure an environment variable
7272

73-
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:
73+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
7474

75-
### [Windows command prompt](#tab/windowscommandprompt)
76-
77-
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:
75+
1. Set an 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.
7876

77+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
78+
7979
```cmd
80-
setx AZURE_APPCONFIG_CONNECTION_STRING "<app-configuration-store-connection-string>"
80+
setx AZURE_APPCONFIG_ENDPOINT "endpoint-of-your-app-configuration-store"
8181
```
82-
83-
### [PowerShell](#tab/powershell)
84-
85-
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:
86-
87-
```azurepowershell
88-
$Env:AZURE_APPCONFIG_CONNECTION_STRING = "<app-configuration-store-connection-string>"
82+
83+
If you use PowerShell, run the following command:
84+
85+
```powershell
86+
$Env:AZURE_APPCONFIG_ENDPOINT = "endpoint-of-your-app-configuration-store"
8987
```
90-
91-
### [macOS](#tab/unix)
92-
93-
If you use macOS, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
94-
95-
```console
96-
export AZURE_APPCONFIG_CONNECTION_STRING='<app-configuration-store-connection-string>'
88+
89+
If you use macOS or Linux, run the following command:
90+
91+
```bash
92+
export AZURE_APPCONFIG_ENDPOINT='<endpoint-of-your-app-configuration-store>'
9793
```
98-
99-
### [Linux](#tab/linux)
100-
101-
If you use Linux, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
102-
103-
```console
104-
export AZURE_APPCONFIG_CONNECTION_STRING='<app-configuration-store-connection-string>'
94+
95+
### [Connection string](#tab/connection-string)
96+
97+
Set an 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.
98+
99+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
100+
101+
```cmd
102+
setx AZURE_APPCONFIG_CONNECTION_STRING "<connection-string-of-your-app-configuration-store>"
105103
```
106-
104+
105+
If you use PowerShell, run the following command:
106+
107+
```powershell
108+
$Env:AZURE_APPCONFIG_CONNECTION_STRING = "connection-string-of-your-app-configuration-store"
109+
```
110+
111+
If you use macOS or Linux, run the following command:
112+
113+
```bash
114+
export AZURE_APPCONFIG_CONNECTION_STRING='<connection-string-of-your-app-configuration-store>'
115+
```
116+
---
117+
107118
1. Print out the value of the environment variable to validate that it is set properly with the command below.
108119

109-
### [Windows command prompt](#tab/windowscommandprompt)
110-
111-
Using the Windows command prompt, restart the command prompt to allow the change to take effect and run the following command:
120+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
112121

113122
```cmd
114-
echo %AZURE_APPCONFIG_CONNECTION_STRING%
123+
echo AZURE_APPCONFIG_ENDPOINT
115124
```
116-
117-
### [PowerShell](#tab/powershell)
118-
119-
If you use Windows PowerShell, run the following command:
120-
121-
```azurepowershell
122-
$Env:AZURE_APPCONFIG_CONNECTION_STRING
125+
126+
If you use PowerShell, run the following command:
127+
128+
```powershell
129+
$Env:AZURE_APPCONFIG_ENDPOINT
123130
```
124-
125-
### [macOS](#tab/unix)
126-
127-
If you use macOS, run the following command:
128-
129-
```console
130-
echo "$AZURE_APPCONFIG_CONNECTION_STRING"
131+
132+
If you use macOS or Linux, run the following command:
133+
134+
```bash
135+
export AZURE_APPCONFIG_ENDPOINT
131136
```
132137

133-
### [Linux](#tab/linux)
134-
135-
If you use Linux, run the following command:
138+
### [Connection string](#tab/connection-string)
136139

137-
```console
138-
echo "$AZURE_APPCONFIG_CONNECTION_STRING"
140+
```cmd
141+
echo AZURE_APPCONFIG_CONNECTION_STRING
142+
```
143+
144+
If you use PowerShell, run the following command:
145+
146+
```powershell
147+
$Env:AZURE_APPCONFIG_CONNECTION_STRING
139148
```
149+
150+
If you use macOS or Linux, run the following command:
151+
152+
```bash
153+
export AZURE_APPCONFIG_CONNECTION_STRING
154+
```
155+
---
140156

141157
## Code samples
142158

@@ -158,12 +174,31 @@ Learn below how to:
158174

159175
### Connect to an App Configuration store
160176

161-
The following code snippet creates an instance of **AppConfigurationClient** using the connection string stored in your environment variables.
177+
The following code snippet creates an instance of **AppConfigurationClient**. You can connect to your App Configuration store using Microsoft Entra ID (recommended), or a connection string.
178+
179+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
180+
181+
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.
182+
183+
```javascript
184+
const azureIdentity = require("@azure/identity");
185+
const appConfig = require("@azure/app-configuration");
186+
187+
const credential = new azureIdentity.DefaultAzureCredential();
188+
const client = new appConfig.AppConfigurationClient(
189+
process.env.AZURE_APPCONFIG_ENDPOINT,
190+
credential
191+
);
192+
193+
```
194+
195+
### [Connection string](#tab/connection-string)
162196

163197
```javascript
164198
const connection_string = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
165199
const client = new AppConfigurationClient(connection_string);
166200
```
201+
---
167202

168203
### Get a configuration setting
169204

@@ -253,6 +288,67 @@ In this example, you created a Node.js app that uses the Azure App Configuration
253288

254289
At this point, your *app-configuration-example.js* file should have the following code:
255290

291+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
292+
293+
294+
```javascript
295+
const { DefaultAzureCredential } = require("@azure/identity");
296+
const { AppConfigurationClient } = require("@azure/app-configuration");
297+
298+
async function run() {
299+
console.log("Azure App Configuration - JavaScript example");
300+
301+
const credential = new DefaultAzureCredential();
302+
const client = new AppConfigurationClient(
303+
process.env.AZURE_APPCONFIG_ENDPOINT,
304+
credential
305+
);
306+
307+
const retrievedConfigSetting = await client.getConfigurationSetting({
308+
key: "TestApp:Settings:Message"
309+
});
310+
console.log("\nRetrieved configuration setting:");
311+
console.log(`Key: ${retrievedConfigSetting.key}, Value: ${retrievedConfigSetting.value}`);
312+
313+
const configSetting = {
314+
key: "TestApp:Settings:NewSetting",
315+
value: "New setting value"
316+
};
317+
const addedConfigSetting = await client.addConfigurationSetting(configSetting);
318+
console.log("Added configuration setting:");
319+
console.log(`Key: ${addedConfigSetting.key}, Value: ${addedConfigSetting.value}`);
320+
321+
const filteredSettingsList = client.listConfigurationSettings({
322+
keyFilter: "TestApp*"
323+
});
324+
console.log("Retrieved list of configuration settings:");
325+
for await (const filteredSetting of filteredSettingsList) {
326+
console.log(`Key: ${filteredSetting.key}, Value: ${filteredSetting.value}`);
327+
}
328+
329+
const lockedConfigSetting = await client.setReadOnly(addedConfigSetting, true /** readOnly */);
330+
console.log(`Read-only status for ${lockedConfigSetting.key}: ${lockedConfigSetting.isReadOnly}`);
331+
332+
const unlockedConfigSetting = await client.setReadOnly(lockedConfigSetting, false /** readOnly */);
333+
console.log(`Read-only status for ${unlockedConfigSetting.key}: ${unlockedConfigSetting.isReadOnly}`);
334+
335+
addedConfigSetting.value = "Value has been updated!";
336+
const updatedConfigSetting = await client.setConfigurationSetting(addedConfigSetting);
337+
console.log("Updated configuration setting:");
338+
console.log(`Key: ${updatedConfigSetting.key}, Value: ${updatedConfigSetting.value}`);
339+
340+
const deletedConfigSetting = await client.deleteConfigurationSetting({
341+
key: "TestApp:Settings:NewSetting"
342+
});
343+
console.log("Deleted configuration setting:");
344+
console.log(`Key: ${deletedConfigSetting.key}, Value: ${deletedConfigSetting.value}`);
345+
}
346+
347+
run().catch(console.error);
348+
```
349+
350+
### [Connection string](#tab/connection-string)
351+
256352
```javascript
257353
const { AppConfigurationClient } = require("@azure/app-configuration");
258354

@@ -304,6 +400,7 @@ async function run() {
304400

305401
run().catch(console.error);
306402
```
403+
---
307404

308405
In your console window, navigate to the directory containing the *app-configuration-example.js* file and execute the following command to run the app:
309406

0 commit comments

Comments
 (0)