diff --git a/codex-rs/tui_app_server/src/onboarding/auth.rs b/codex-rs/tui_app_server/src/onboarding/auth.rs index 612fdbe2ace..948e0cd9b72 100644 --- a/codex-rs/tui_app_server/src/onboarding/auth.rs +++ b/codex-rs/tui_app_server/src/onboarding/auth.rs @@ -771,6 +771,7 @@ impl AuthModeWidget { .await { Ok(LoginAccountResponse::Chatgpt { login_id, auth_url }) => { + maybe_open_auth_url_in_browser(&request_handle, &auth_url); *error.write().unwrap() = None; *sign_in_state.write().unwrap() = SignInState::ChatGptContinueInBrowser(ContinueInBrowserState { @@ -880,6 +881,16 @@ impl WidgetRef for AuthModeWidget { } } +pub(super) fn maybe_open_auth_url_in_browser(request_handle: &AppServerRequestHandle, url: &str) { + if !matches!(request_handle, AppServerRequestHandle::InProcess(_)) { + return; + } + + if let Err(err) = webbrowser::open(url) { + tracing::warn!("failed to open browser for login URL: {err}"); + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/codex-rs/tui_app_server/src/onboarding/auth/headless_chatgpt_login.rs b/codex-rs/tui_app_server/src/onboarding/auth/headless_chatgpt_login.rs index 33afe740b82..d0834fe1662 100644 --- a/codex-rs/tui_app_server/src/onboarding/auth/headless_chatgpt_login.rs +++ b/codex-rs/tui_app_server/src/onboarding/auth/headless_chatgpt_login.rs @@ -29,6 +29,7 @@ use super::ContinueInBrowserState; use super::ContinueWithDeviceCodeState; use super::SignInState; use super::mark_url_hyperlink; +use super::maybe_open_auth_url_in_browser; use super::onboarding_request_id; pub(super) fn start_headless_chatgpt_login(widget: &mut AuthModeWidget) { @@ -289,6 +290,7 @@ async fn fallback_to_browser_login( .await { Ok(LoginAccountResponse::Chatgpt { login_id, auth_url }) => { + maybe_open_auth_url_in_browser(&request_handle, &auth_url); *error.write().unwrap() = None; let _updated = set_device_code_state_for_active_attempt( &sign_in_state,