Skip to content

Commit 6000b73

Browse files
use DefaultAzureCredential instead of AzureCliCredential (#3860)
1 parent 6a88c7b commit 6000b73

113 files changed

Lines changed: 435 additions & 105 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dotnet/samples/A2AClientServer/A2AServer/HostAgentFactory.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ internal static class HostAgentFactory
1414
{
1515
internal static async Task<(AIAgent, AgentCard)> CreateFoundryHostAgentAsync(string agentType, string model, string endpoint, string assistantId, IList<AITool>? tools = null)
1616
{
17-
var persistentAgentsClient = new PersistentAgentsClient(endpoint, new AzureCliCredential());
17+
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
18+
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
19+
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
20+
var persistentAgentsClient = new PersistentAgentsClient(endpoint, new DefaultAzureCredential());
1821
PersistentAgent persistentAgent = await persistentAgentsClient.Administration.GetAgentAsync(assistantId);
1922

2023
AIAgent agent = await persistentAgentsClient

dotnet/samples/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public static void Initialize(IConfiguration configuration)
2424
string endpoint = configuration["AZURE_OPENAI_ENDPOINT"] ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
2525
s_deploymentName = configuration["AZURE_OPENAI_DEPLOYMENT_NAME"] ?? throw new InvalidOperationException("AZURE_OPENAI_DEPLOYMENT_NAME is not set.");
2626

27+
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
28+
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
29+
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
2730
s_azureOpenAIClient = new AzureOpenAIClient(
2831
new Uri(endpoint),
2932
new DefaultAzureCredential());

dotnet/samples/AGUIClientServer/AGUIServer/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
string deploymentName = builder.Configuration["AZURE_OPENAI_DEPLOYMENT_NAME"] ?? throw new InvalidOperationException("AZURE_OPENAI_DEPLOYMENT_NAME is not set.");
2020

2121
// Create the AI agent with tools
22+
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
23+
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
24+
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
2225
var agent = new AzureOpenAIClient(
2326
new Uri(endpoint),
2427
new DefaultAzureCredential())

dotnet/samples/AGUIWebChat/Server/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
string deploymentName = builder.Configuration["AZURE_OPENAI_DEPLOYMENT_NAME"] ?? throw new InvalidOperationException("AZURE_OPENAI_DEPLOYMENT_NAME is not set.");
2020

2121
// Create the AI agent
22+
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
23+
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
24+
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
2225
AzureOpenAIClient azureOpenAIClient = new(
2326
new Uri(endpoint),
2427
new DefaultAzureCredential());

dotnet/samples/Durable/Agents/AzureFunctions/01_SingleAgent/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
// Use Azure Key Credential if provided, otherwise use Azure CLI Credential.
2121
string? azureOpenAiKey = System.Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY");
22+
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
23+
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
24+
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
2225
AzureOpenAIClient client = !string.IsNullOrEmpty(azureOpenAiKey)
2326
? new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(azureOpenAiKey))
24-
: new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential());
27+
: new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential());
2528

2629
// Set up an AI agent following the standard Microsoft Agent Framework pattern.
2730
const string JokerName = "Joker";

dotnet/samples/Durable/Agents/AzureFunctions/02_AgentOrchestration_Chaining/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
// Use Azure Key Credential if provided, otherwise use Azure CLI Credential.
2121
string? azureOpenAiKey = System.Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY");
22+
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
23+
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
24+
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
2225
AzureOpenAIClient client = !string.IsNullOrEmpty(azureOpenAiKey)
2326
? new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(azureOpenAiKey))
24-
: new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential());
27+
: new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential());
2528

2629
// Single agent used by the orchestration to demonstrate sequential calls on the same session.
2730
const string WriterName = "WriterAgent";

dotnet/samples/Durable/Agents/AzureFunctions/03_AgentOrchestration_Concurrency/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
// Use Azure Key Credential if provided, otherwise use Azure CLI Credential.
2121
string? azureOpenAiKey = System.Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY");
22+
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
23+
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
24+
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
2225
AzureOpenAIClient client = !string.IsNullOrEmpty(azureOpenAiKey)
2326
? new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(azureOpenAiKey))
24-
: new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential());
27+
: new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential());
2528

2629
// Two agents used by the orchestration to demonstrate concurrent execution.
2730
const string PhysicistName = "PhysicistAgent";

dotnet/samples/Durable/Agents/AzureFunctions/04_AgentOrchestration_Conditionals/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
// Use Azure Key Credential if provided, otherwise use Azure CLI Credential.
2121
string? azureOpenAiKey = System.Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY");
22+
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
23+
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
24+
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
2225
AzureOpenAIClient client = !string.IsNullOrEmpty(azureOpenAiKey)
2326
? new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(azureOpenAiKey))
24-
: new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential());
27+
: new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential());
2528

2629
// Two agents used by the orchestration to demonstrate conditional logic.
2730
const string SpamDetectionName = "SpamDetectionAgent";

dotnet/samples/Durable/Agents/AzureFunctions/05_AgentOrchestration_HITL/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
// Use Azure Key Credential if provided, otherwise use Azure CLI Credential.
2121
string? azureOpenAiKey = System.Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY");
22+
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
23+
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
24+
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
2225
AzureOpenAIClient client = !string.IsNullOrEmpty(azureOpenAiKey)
2326
? new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(azureOpenAiKey))
24-
: new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential());
27+
: new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential());
2528

2629
// Single agent used by the orchestration to demonstrate human-in-the-loop workflow.
2730
const string WriterName = "WriterAgent";

dotnet/samples/Durable/Agents/AzureFunctions/06_LongRunningTools/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323

2424
// Use Azure Key Credential if provided, otherwise use Azure CLI Credential.
2525
string? azureOpenAiKey = System.Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY");
26+
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
27+
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
28+
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
2629
AzureOpenAIClient client = !string.IsNullOrEmpty(azureOpenAiKey)
2730
? new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(azureOpenAiKey))
28-
: new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential());
31+
: new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential());
2932

3033
// Agent used by the orchestration to write content.
3134
const string WriterAgentName = "Writer";

0 commit comments

Comments
 (0)