mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-20 06:56:17 -05:00
refactor: simplify SAML browser selection
This commit is contained in:
1 file changed
+32
-19
@@ -15,7 +15,7 @@ use gpapi::{
|
|||||||
error::PortalError,
|
error::PortalError,
|
||||||
gateway::{GatewayLogin, SessionExtensionAuth, gateway_login},
|
gateway::{GatewayLogin, SessionExtensionAuth, gateway_login},
|
||||||
gp_params::{ClientOs, GpParams},
|
gp_params::{ClientOs, GpParams},
|
||||||
portal::{Prelogin, StandardPrelogin, prelogin, retrieve_config},
|
portal::{Prelogin, SamlPrelogin, StandardPrelogin, prelogin, retrieve_config},
|
||||||
process::{
|
process::{
|
||||||
auth_launcher::SamlAuthLauncher,
|
auth_launcher::SamlAuthLauncher,
|
||||||
users::{get_non_root_user, get_user_by_name},
|
users::{get_non_root_user, get_user_by_name},
|
||||||
@@ -185,6 +185,36 @@ impl ConnectArgs {
|
|||||||
Os::Mac => host_utils::get_macos_os_string(),
|
Os::Mac => host_utils::get_macos_os_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn saml_auth_browser<'a>(&'a self, prelogin: &SamlPrelogin) -> anyhow::Result<Option<&'a str>> {
|
||||||
|
if prelogin.support_default_browser() {
|
||||||
|
return Ok(self.default_browser_saml_auth_browser());
|
||||||
|
}
|
||||||
|
|
||||||
|
self.embedded_saml_auth_browser()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "webview-auth")]
|
||||||
|
fn default_browser_saml_auth_browser(&self) -> Option<&str> {
|
||||||
|
self.browser.as_deref()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "webview-auth"))]
|
||||||
|
fn default_browser_saml_auth_browser(&self) -> Option<&str> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "webview-auth")]
|
||||||
|
fn embedded_saml_auth_browser(&self) -> anyhow::Result<Option<&str>> {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "webview-auth"))]
|
||||||
|
fn embedded_saml_auth_browser(&self) -> anyhow::Result<Option<&str>> {
|
||||||
|
bail!(
|
||||||
|
"The server does not support authentication via the default browser and the gpclient is not built with the `webview-auth` feature"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct ConnectHandler<'a> {
|
pub(crate) struct ConnectHandler<'a> {
|
||||||
@@ -539,24 +569,7 @@ impl<'a> ConnectHandler<'a> {
|
|||||||
|
|
||||||
match prelogin {
|
match prelogin {
|
||||||
Prelogin::Saml(prelogin) => {
|
Prelogin::Saml(prelogin) => {
|
||||||
let browser = if prelogin.support_default_browser() {
|
let browser = self.args.saml_auth_browser(prelogin)?;
|
||||||
#[cfg(feature = "webview-auth")]
|
|
||||||
{
|
|
||||||
self.args.browser.as_deref()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "webview-auth"))]
|
|
||||||
{
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else if !cfg!(feature = "webview-auth") {
|
|
||||||
bail!(
|
|
||||||
"The server does not support authentication via the default browser and the gpclient is not built with the `webview-auth` feature"
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let os_version = self.args.os_version();
|
let os_version = self.args.os_version();
|
||||||
let verbose = self.shared_args.verbose.to_verbose_arg();
|
let verbose = self.shared_args.verbose.to_verbose_arg();
|
||||||
let user_agent = self.user_agent();
|
let user_agent = self.user_agent();
|
||||||
|
|||||||
Reference in new issue
Block a user