Skip to content

Commit 8461f0a

Browse files
Copilotheaths
andauthored
[Identity] Add --no-prompt flag to AzureDeveloperCliCredential to prevent hanging with AZD_DEBUG (#2914)
When the `AZD_DEBUG` environment variable is set, the `azd auth token` subprocess hangs indefinitely waiting for user input: ```shell $ AZD_DEBUG=1 azd auth token --output json --scope https://search.azure.com/.default ? Debugger Ready? (pid: 259503) (Y/n) ``` This causes `AzureDeveloperCliCredential.get_token()` to timeout when debugging is enabled. This PR adds the `--no-prompt` flag to the `azd auth token` command to prevent interactive prompts and ensure the credential works reliably regardless of debug settings. **Changes:** - Added `--no-prompt` to the azd command construction in `get_token()` - Updated test assertions to verify the flag is included in generated commands **Example command before:** ``` azd auth token -o json --scope https://management.azure.com/.default ``` **Example command after:** ``` azd auth token -o json --no-prompt --scope https://management.azure.com/.default ``` All existing tests pass and the change is backward compatible. Fixes #2910. <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: heaths <[email protected]>
1 parent 2d7035a commit 8461f0a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

sdk/identity/azure_identity/src/azure_developer_cli_credential.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl TokenCredential for AzureDeveloperCliCredential {
118118
"at least one scope required",
119119
));
120120
}
121-
let mut command = OsString::from("azd auth token -o json");
121+
let mut command = OsString::from("azd auth token -o json --no-prompt");
122122
for scope in scopes {
123123
validate_scope(scope)?;
124124
command.push(" --scope ");
@@ -170,12 +170,15 @@ mod tests {
170170
if cfg!(target_os = "windows") {
171171
assert_eq!(program.to_string_lossy(), "cmd");
172172
assert_eq!(args[0], "/C");
173-
assert!(args[1]
174-
.starts_with(&format!("cd {system_root} && azd auth token -o json")));
173+
assert!(args[1].starts_with(&format!(
174+
"cd {system_root} && azd auth token -o json --no-prompt"
175+
)));
175176
} else {
176177
assert_eq!(program, "/bin/sh");
177178
assert_eq!(args[0], "-c");
178-
assert!(args[1].starts_with("cd /bin && azd auth token -o json"));
179+
assert!(
180+
args[1].starts_with("cd /bin && azd auth token -o json --no-prompt")
181+
);
179182
}
180183
for scope in LIVE_TEST_SCOPES {
181184
assert!(args[1].contains(&format!(" --scope {scope}")));

0 commit comments

Comments
 (0)