From 7cdffb94b93469335ce189d3dc29d3c8d8e67c6d Mon Sep 17 00:00:00 2001 From: ZelinWang Date: Mon, 20 Jan 2025 11:09:17 +0800 Subject: [PATCH 1/4] Add azure powershell credential --- shell/agents/Microsoft.Azure.Agent/AzureAgent.cs | 2 +- shell/agents/Microsoft.Azure.Agent/ChatSession.cs | 4 ++-- shell/agents/Microsoft.Azure.Agent/Schema.cs | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/shell/agents/Microsoft.Azure.Agent/AzureAgent.cs b/shell/agents/Microsoft.Azure.Agent/AzureAgent.cs index 948bea49..f1bb3eb0 100644 --- a/shell/agents/Microsoft.Azure.Agent/AzureAgent.cs +++ b/shell/agents/Microsoft.Azure.Agent/AzureAgent.cs @@ -194,7 +194,7 @@ public async Task RefreshChatAsync(IShell shell, bool force) if (inner is CredentialUnavailableException) { host.WriteErrorLine($"Failed to start a chat session: Access token not available."); - host.WriteErrorLine($"The '{Name}' agent depends on the Azure CLI credential to acquire access token. Please run 'az login' from a command-line shell to setup account. Once you've successfully logged in, run '/refresh' to start a new conversation."); + host.WriteErrorLine($"The '{Name}' agent depends on the Azure CLI credential or Azure PowerShell credential to acquire access token. Please run 'az login' or 'Connect-AzAccount' from a command-line shell to setup account. Once you've successfully logged in, run '/refresh' to start a new conversation."); return; } diff --git a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs index 448b18a2..0b5c11c1 100644 --- a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs +++ b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs @@ -115,8 +115,8 @@ private async Task SetupNewChat(IStatusContext context, CancellationToke { try { - context.Status("Get Azure CLI login token ..."); - // Get an access token from the AzCLI login, using the specific audience guid. + context.Status("Get Azure CLI or Azure PowerShell login token ..."); + // Get an access token from the AzureCLI login or Azure PowerShell login, using the specific audience guid. await _accessToken.CreateOrRenewTokenAsync(cancellationToken); context.Status("Check Copilot authorization ..."); diff --git a/shell/agents/Microsoft.Azure.Agent/Schema.cs b/shell/agents/Microsoft.Azure.Agent/Schema.cs index 0aca7981..15a2da3d 100644 --- a/shell/agents/Microsoft.Azure.Agent/Schema.cs +++ b/shell/agents/Microsoft.Azure.Agent/Schema.cs @@ -386,8 +386,10 @@ internal async Task CreateOrRenewTokenAsync(CancellationToken cancellationToken) if (needRefresh) { - _accessToken = await new AzureCliCredential() - .GetTokenAsync(_tokenContext, cancellationToken); + _accessToken = await new ChainedTokenCredential( + new AzureCliCredential(), + new AzurePowerShellCredential() + ).GetTokenAsync(_tokenContext, cancellationToken); } } catch (Exception e) when (e is not OperationCanceledException) From b9890bc0fcf26a23e199a53f71c25dbe3ec3531a Mon Sep 17 00:00:00 2001 From: ZelinWang Date: Mon, 20 Jan 2025 11:20:46 +0800 Subject: [PATCH 2/4] update --- shell/agents/Microsoft.Azure.Agent/ChatSession.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs index 0b5c11c1..4d1e2543 100644 --- a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs +++ b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs @@ -116,7 +116,7 @@ private async Task SetupNewChat(IStatusContext context, CancellationToke try { context.Status("Get Azure CLI or Azure PowerShell login token ..."); - // Get an access token from the AzureCLI login or Azure PowerShell login, using the specific audience guid. + // Get an access token from the Azure CLI login or Azure PowerShell login, using the specific audience guid. await _accessToken.CreateOrRenewTokenAsync(cancellationToken); context.Status("Check Copilot authorization ..."); From 2b310e85c6d79a81d811662b466168ca20676e22 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 21 Jan 2025 10:42:49 -0800 Subject: [PATCH 3/4] Update shell/agents/Microsoft.Azure.Agent/ChatSession.cs --- shell/agents/Microsoft.Azure.Agent/ChatSession.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs index 4d1e2543..76e2931f 100644 --- a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs +++ b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs @@ -115,7 +115,7 @@ private async Task SetupNewChat(IStatusContext context, CancellationToke { try { - context.Status("Get Azure CLI or Azure PowerShell login token ..."); + context.Status("Get Azure login token ..."); // Get an access token from the Azure CLI login or Azure PowerShell login, using the specific audience guid. await _accessToken.CreateOrRenewTokenAsync(cancellationToken); From 8714b0c397147d81e29da067bcbbcb5096934ed6 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 21 Jan 2025 10:43:01 -0800 Subject: [PATCH 4/4] Update shell/agents/Microsoft.Azure.Agent/ChatSession.cs --- shell/agents/Microsoft.Azure.Agent/ChatSession.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs index 76e2931f..064d73be 100644 --- a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs +++ b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs @@ -116,7 +116,7 @@ private async Task SetupNewChat(IStatusContext context, CancellationToke try { context.Status("Get Azure login token ..."); - // Get an access token from the Azure CLI login or Azure PowerShell login, using the specific audience guid. + // Get an access token from the Azure CLI/PowerShell login, using the specific audience guid. await _accessToken.CreateOrRenewTokenAsync(cancellationToken); context.Status("Check Copilot authorization ...");