Skip to content

Commit 143149f

Browse files
MaryanneNjeriMaryanne Gichohizhenlan
authored
Update quickstart sample app to use EntraID authentication (#1117)
* Update quickstart sample app to use EntraID authentication * Update examples/QuickStart/JavaScript/QuickStartApp/QuickStartApp.js Co-authored-by: Zhenlan Wang <zhenlwa@microsoft.com> * Update examples/QuickStart/Python/QuickStartApp/QuickStartApp.py Co-authored-by: Zhenlan Wang <zhenlwa@microsoft.com> * Updated package version --------- Co-authored-by: Maryanne Gichohi <mgichohi@microsoft.com> Co-authored-by: Zhenlan Wang <zhenlwa@microsoft.com>
1 parent 223b1ea commit 143149f

7 files changed

Lines changed: 23 additions & 10 deletions

File tree

examples/QuickStart/DotNet/QuickStartApp/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using Microsoft.Extensions.Configuration;
2+
using Azure.Identity;
3+
4+
Uri endpoint = new(Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_ENDPOINT") ??
5+
throw new InvalidOperationException("The environment variable 'AZURE_APPCONFIGURATION_ENDPOINT' is not set or is empty."));
26

37
var builder = new ConfigurationBuilder();
48
builder.AddAzureAppConfiguration(options =>
59
{
6-
options.Connect(Environment.GetEnvironmentVariable("AZURE_APPCONFIG_CONNECTION_STRING"))
10+
options.Connect(endpoint, new DefaultAzureCredential())
711
.Select("QuickStartApp*");
812
});
913

examples/QuickStart/DotNet/QuickStartApp/QuickStartApp.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="6.0.1" />
11+
<PackageReference Include="Azure.Identity" Version="1.14.0" />
12+
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.4.0" />
1213
</ItemGroup>
1314

1415
</Project>

examples/QuickStart/JavaScript/QuickStartApp/QuickStartApp.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
const { load } = require("@azure/app-configuration-provider");
2-
const connectionString = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
2+
const { DefaultAzureCredential } = require("@azure/identity");
3+
4+
const endpoint = process.env.AZURE_APPCONFIGURATION_ENDPOINT;
35

46
async function run() {
57
console.log("Sample 1: Load key-values with default selector");
68

7-
// Connect to Azure App Configuration using a connection string and load all key-values with null label.
8-
const settings = await load(connectionString);
9+
// Connect to Azure App Configuration using Microsoft Entra ID authentication and load all key-values with null label.
10+
const settings = await load(endpoint, new DefaultAzureCredential());
911

1012
console.log("---Consume configuration as a Map---");
1113
// Find the key "message" and print its value.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"dependencies": {
3-
"@azure/app-configuration-provider": "latest"
3+
"@azure/app-configuration-provider": "latest",
4+
"@azure/identity": "latest"
45
}
56
}

examples/QuickStart/JavaSpring/QuickStart/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<groupId>com.azure.spring</groupId>
1818
<artifactId>spring-cloud-azure-appconfiguration-config-web</artifactId>
1919
</dependency>
20+
<dependency>
21+
<groupId>com.azure.spring</groupId>
22+
<artifactId>azure-identity-spring</artifactId>
23+
</dependency>
2024
</dependencies>
2125

2226
<dependencyManagement>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
spring.application.name=QuickStart
22
# Either a connection string or endpoint needs to be provided per store.
33
# All possible configurations can be found in the [README](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/spring/spring-cloud-azure-starter-appconfiguration-config)
4-
spring.cloud.azure.appconfiguration.stores[0].connection-string= ${AZURE_APPCONFIG_CONNECTION_STRING}
4+
spring.cloud.azure.appconfiguration.stores[0].endpoint= ${AZURE_APPCONFIGURATION_ENDPOINT}

examples/QuickStart/Python/QuickStartApp/QuickStartApp.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
load,
33
SettingSelector
44
)
5+
from azure.identity import DefaultAzureCredential
56
import os
67

7-
connection_string = os.environ.get("AZURE_APPCONFIG_CONNECTION_STRING")
8+
endpoint = os.environ.get("AZURE_APPCONFIGURATION_ENDPOINT")
89

9-
# Connect to Azure App Configuration using a connection string.
10-
config = load(connection_string=connection_string)
10+
# Connect to Azure App Configuration using Microsoft Entra ID authentication.
11+
config = load(endpoint=endpoint, credential=DefaultAzureCredential())
1112

1213
# Find the key "message" and print its value.
1314
print(config["message"])

0 commit comments

Comments
 (0)