feat: support specify the browser to use

Related: #405, #407, #397
This commit is contained in:
Kevin Yue
2024-08-14 21:27:01 +08:00
parent c2a6a436a5
commit 9460d498fc
7 changed files with 108 additions and 13 deletions

View File

@@ -19,6 +19,7 @@ pub struct SamlAuthLauncher<'a> {
ignore_tls_errors: bool,
clean: bool,
default_browser: bool,
external_browser: Option<&'a str>,
}
impl<'a> SamlAuthLauncher<'a> {
@@ -35,6 +36,7 @@ impl<'a> SamlAuthLauncher<'a> {
ignore_tls_errors: false,
clean: false,
default_browser: false,
external_browser: None,
}
}
@@ -88,6 +90,11 @@ impl<'a> SamlAuthLauncher<'a> {
self
}
pub fn external_browser(mut self, external_browser: Option<&'a str>) -> Self {
self.external_browser = external_browser;
self
}
/// Launch the authenticator binary as the current user or SUDO_USER if available.
pub async fn launch(self) -> anyhow::Result<Option<Credential>> {
let mut auth_cmd = Command::new(GP_AUTH_BINARY);
@@ -133,6 +140,10 @@ impl<'a> SamlAuthLauncher<'a> {
auth_cmd.arg("--default-browser");
}
if let Some(external_browser) = self.external_browser {
auth_cmd.arg("--external-browser").arg(external_browser);
}
let mut non_root_cmd = auth_cmd.into_non_root()?;
let output = non_root_cmd
.kill_on_drop(true)