Skip to content

Commit

Permalink
Add support to Azure PowerShell login credential (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzelin007 authored Jan 21, 2025
1 parent d16ac5a commit 1c4a2e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion shell/agents/Microsoft.Azure.Agent/AzureAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions shell/agents/Microsoft.Azure.Agent/ChatSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ private async Task<string> 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 login token ...");
// Get an access token from the Azure CLI/PowerShell login, using the specific audience guid.
await _accessToken.CreateOrRenewTokenAsync(cancellationToken);

context.Status("Check Copilot authorization ...");
Expand Down
6 changes: 4 additions & 2 deletions shell/agents/Microsoft.Azure.Agent/Schema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1c4a2e8

Please sign in to comment.