From 9bf492f95340717b33314eea102114bcdc6c8485 Mon Sep 17 00:00:00 2001 From: BuriKizilkaya Date: Tue, 1 Dec 2026 14:07:24 +0100 Subject: [PATCH] fix: open login browser on Windows --- src/adapters/outbound/dataverse/auth.rs | 39 ++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/adapters/outbound/dataverse/auth.rs b/src/adapters/outbound/dataverse/auth.rs index 9d1f017..8e73d2e 100644 --- a/src/adapters/outbound/dataverse/auth.rs +++ b/src/adapters/outbound/dataverse/auth.rs @@ -360,6 +360,27 @@ fn urldecode(value: &str) -> String { String::from_utf8_lossy(&decoded).into_owned() } +#[derive(Clone, Copy)] +enum BrowserPlatform { + #[cfg(target_os = "macos")] + MacOs, + #[cfg(any(target_os = "windows", test))] + Windows, + #[cfg(all(not(target_os = "macos"), not(target_os = "windows")))] + Unix, +} + +fn browser_launcher_candidates(platform: BrowserPlatform) -> &'static [&'static str] { + match platform { + #[cfg(target_os = "macos")] + BrowserPlatform::MacOs => &["open"], + #[cfg(any(target_os = "windows", test))] + BrowserPlatform::Windows => &["explorer.exe"], + #[cfg(all(not(target_os = "macos"), not(target_os = "windows")))] + BrowserPlatform::Unix => &["xdg-open", "open"], + } +} + /// Opens the authorization URL with `$BROWSER` or the platform browser launcher. fn open_browser(url: &str, browser: Option<&str>) -> io::Result<()> { if let Some(browser) = browser { @@ -412,11 +433,13 @@ fn open_browser(url: &str, browser: Option<&str>) -> io::Result<()> { } #[cfg(target_os = "macos")] - let candidates: &[&str] = &["open"]; - #[cfg(not(target_os = "macos"))] - let candidates: &[&str] = &["xdg-open", "open"]; + let platform = BrowserPlatform::MacOs; + #[cfg(target_os = "windows")] + let platform = BrowserPlatform::Windows; + #[cfg(all(not(target_os = "macos"), not(target_os = "windows")))] + let platform = BrowserPlatform::Unix; - for program in candidates { + for program in browser_launcher_candidates(platform) { if Command::new(program).arg(url).spawn().is_ok() { return Ok(()); } @@ -508,6 +531,14 @@ mod tests { use super::*; use serde_json::json; + #[test] + fn windows_uses_the_system_browser_launcher() { + assert_eq!( + browser_launcher_candidates(BrowserPlatform::Windows), + &["explorer.exe"] + ); + } + #[test] fn scope_requests_dataverse_delegated_permission_and_offline_access() { let config = json!({"environmentUrl": "https://org.crm4.dynamics.com/"});