Skip to content

Commit 84da2dd

Browse files
authored
Fix AzureDeveloperCliCredential hanging when AZD_DEBUG is set (#52013)
1 parent 402bccd commit 84da2dd

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

sdk/identity/Azure.Identity/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bugs Fixed
1010

11+
- Fixed `AzureDeveloperCliCredential` hanging when the `AZD_DEBUG` environment variable is set by adding the `--no-prompt` flag to prevent interactive prompts ([#52005](https://github.com/Azure/azure-sdk-for-net/issues/52005)).
12+
1113
### Other Changes
1214

1315
## 1.15.0 (2025-08-11)

sdk/identity/Azure.Identity/src/Credentials/AzureDeveloperCliCredential.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ private static void GetFileNameAndArguments(string[] scopes, string tenantId, ou
207207
string scopeArgs = string.Join(" ", scopes.Select(scope => $"--scope {scope}"));
208208
string command = tenantId switch
209209
{
210-
null => $"azd auth token --output json {scopeArgs}",
211-
_ => $"azd auth token --output json {scopeArgs} --tenant-id {tenantId}"
210+
null => $"azd auth token --output json --no-prompt {scopeArgs}",
211+
_ => $"azd auth token --output json --no-prompt {scopeArgs} --tenant-id {tenantId}"
212212
};
213213

214214
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

sdk/identity/Azure.Identity/tests/AzureDeveloperCliCredentialTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ public async Task AuthenticateWithDeveloperCliCredential(
7171
}
7272
}
7373

74+
[Test]
75+
public async Task AuthenticateWithDeveloperCliCredential_IncludesNoPromptFlag()
76+
{
77+
var context = new TokenRequestContext(new[] { Scope });
78+
var (expectedToken, expectedExpiresOn, processOutput) = CredentialTestHelpers.CreateTokenForAzureDeveloperCli();
79+
80+
var testProcess = new TestProcess { Output = processOutput };
81+
AzureDeveloperCliCredential credential =
82+
InstrumentClient(new AzureDeveloperCliCredential(CredentialPipeline.GetInstance(null), new TestProcessService(testProcess, true)));
83+
AccessToken actualToken = await credential.GetTokenAsync(context);
84+
85+
Assert.AreEqual(expectedToken, actualToken.Token);
86+
Assert.AreEqual(expectedExpiresOn, actualToken.ExpiresOn);
87+
Assert.That(testProcess.StartInfo.Arguments, Does.Contain("--no-prompt"));
88+
}
89+
7490
[Test]
7591
public void AuthenticateWithCliCredential_InvalidJsonOutput(
7692
[Values("", "{}", "{\"Some\": false}", "{\"token\": \"token\"}", "{\"expiresOn\" : \"1900-01-01T00:00:00Z\"}")]

0 commit comments

Comments
 (0)