From 0f21a844a4178284ca2a324457d7b251b23cf19d Mon Sep 17 00:00:00 2001
From: manvkaur <67894494+manvkaur@users.noreply.github.com>
Date: Mon, 8 Dec 2025 22:53:27 -0800
Subject: [PATCH] updates for default azure credential and azure identity
package
---
samples/assistant/java/pom.xml | 2 +-
.../AzureAISearchProvider.cs | 15 ++++++++++++++-
.../CosmosDBNoSqlSearchProvider.cs | 15 ++++++++++++++-
.../OpenAIClientFactory.cs | 15 ++++++++++++++-
.../WebJobs.Extensions.OpenAI.csproj | 2 +-
5 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/samples/assistant/java/pom.xml b/samples/assistant/java/pom.xml
index 26cb471e..9c1d6a16 100644
--- a/samples/assistant/java/pom.xml
+++ b/samples/assistant/java/pom.xml
@@ -47,7 +47,7 @@
com.azure
azure-identity
- 1.16.2
+ 1.18.0
diff --git a/src/WebJobs.Extensions.OpenAI.AzureAISearch/AzureAISearchProvider.cs b/src/WebJobs.Extensions.OpenAI.AzureAISearch/AzureAISearchProvider.cs
index 4c4d0134..71b0a01e 100644
--- a/src/WebJobs.Extensions.OpenAI.AzureAISearch/AzureAISearchProvider.cs
+++ b/src/WebJobs.Extensions.OpenAI.AzureAISearch/AzureAISearchProvider.cs
@@ -49,6 +49,19 @@ sealed class AzureAISearchProvider : ISearchProvider
/// Throws ArgumentNullException if logger factory is null.
public AzureAISearchProvider(IConfiguration configuration, ILoggerFactory loggerFactory, IOptions azureAiSearchConfigOptions, AzureComponentFactory azureComponentFactory)
{
+
+#if RELEASE
+ if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AZURE_TOKEN_CREDENTIALS")))
+ {
+ Environment.SetEnvironmentVariable("AZURE_TOKEN_CREDENTIALS", "prod");
+ }
+#else
+ if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AZURE_TOKEN_CREDENTIALS")))
+ {
+ Environment.SetEnvironmentVariable("AZURE_TOKEN_CREDENTIALS", "dev");
+ }
+
+#endif
this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
this.azureComponentFactory = azureComponentFactory ?? throw new ArgumentNullException(nameof(azureComponentFactory));
@@ -331,7 +344,7 @@ SearchClient GetSearchClient(ConnectionInfo connectionInfo)
TokenCredential GetSearchTokenCredential() =>
this.searchConnectionConfigSection.Exists()
? this.azureComponentFactory.CreateTokenCredential(this.searchConnectionConfigSection)
- : new DefaultAzureCredential();
+ : new DefaultAzureCredential(DefaultAzureCredential.DefaultEnvironmentVariableName);
void SetConfigSectionProperties()
{
diff --git a/src/WebJobs.Extensions.OpenAI.CosmosDBNoSqlSearch/CosmosDBNoSqlSearchProvider.cs b/src/WebJobs.Extensions.OpenAI.CosmosDBNoSqlSearch/CosmosDBNoSqlSearchProvider.cs
index 6eddc361..62d0cbfb 100644
--- a/src/WebJobs.Extensions.OpenAI.CosmosDBNoSqlSearch/CosmosDBNoSqlSearchProvider.cs
+++ b/src/WebJobs.Extensions.OpenAI.CosmosDBNoSqlSearch/CosmosDBNoSqlSearchProvider.cs
@@ -44,6 +44,19 @@ public CosmosDBNoSqlSearchProvider(
AzureComponentFactory azureComponentFactory
)
{
+
+#if RELEASE
+ if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AZURE_TOKEN_CREDENTIALS")))
+ {
+ Environment.SetEnvironmentVariable("AZURE_TOKEN_CREDENTIALS", "prod");
+ }
+#else
+ if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AZURE_TOKEN_CREDENTIALS")))
+ {
+ Environment.SetEnvironmentVariable("AZURE_TOKEN_CREDENTIALS", "dev");
+ }
+#endif
+
this.configuration =
configuration ?? throw new ArgumentNullException(nameof(configuration));
this.azureComponentFactory =
@@ -238,7 +251,7 @@ CosmosClient CreateCosmosClient()
return new CosmosClient(
connectionSettingValue, // This is the endpoint URI
- new DefaultAzureCredential(),
+ new DefaultAzureCredential(DefaultAzureCredential.DefaultEnvironmentVariableName),
cosmosClientOptions
);
}
diff --git a/src/WebJobs.Extensions.OpenAI/OpenAIClientFactory.cs b/src/WebJobs.Extensions.OpenAI/OpenAIClientFactory.cs
index 51adb201..fbdf9847 100644
--- a/src/WebJobs.Extensions.OpenAI/OpenAIClientFactory.cs
+++ b/src/WebJobs.Extensions.OpenAI/OpenAIClientFactory.cs
@@ -31,6 +31,19 @@ public OpenAIClientFactory(
AzureComponentFactory azureComponentFactory,
ILoggerFactory loggerFactory)
{
+
+#if RELEASE
+ if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AZURE_TOKEN_CREDENTIALS")))
+ {
+ Environment.SetEnvironmentVariable("AZURE_TOKEN_CREDENTIALS", "prod");
+ }
+#else
+ if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AZURE_TOKEN_CREDENTIALS")))
+ {
+ Environment.SetEnvironmentVariable("AZURE_TOKEN_CREDENTIALS", "dev");
+ }
+#endif
+
this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
this.azureComponentFactory = azureComponentFactory ?? throw new ArgumentNullException(nameof(azureComponentFactory));
this.logger = loggerFactory?.CreateLogger() ?? throw new ArgumentNullException(nameof(loggerFactory));
@@ -118,7 +131,7 @@ AzureOpenAIClient CreateClientFromConfigSection(string aiConnectionName)
TokenCredential tokenCredential = section.Exists() ?
this.azureComponentFactory.CreateTokenCredential(section) :
- new DefaultAzureCredential();
+ new DefaultAzureCredential(DefaultAzureCredential.DefaultEnvironmentVariableName);
return this.CreateAzureOpenAIClientWithTokenCredential(this.aiEndpoint, tokenCredential);
}
}
diff --git a/src/WebJobs.Extensions.OpenAI/WebJobs.Extensions.OpenAI.csproj b/src/WebJobs.Extensions.OpenAI/WebJobs.Extensions.OpenAI.csproj
index 0f4fbb48..dd79db6a 100644
--- a/src/WebJobs.Extensions.OpenAI/WebJobs.Extensions.OpenAI.csproj
+++ b/src/WebJobs.Extensions.OpenAI/WebJobs.Extensions.OpenAI.csproj
@@ -7,7 +7,7 @@
-
+