Merge branch 'dev' into gpauth_windows

This commit is contained in:
Kevin Yue committed 2025-12-13 23:56:16 +08:00
commit 0669447aed
91 files changed
+5486 -3171

No files matched your search

+5 -4
View File
@@ -8,6 +8,7 @@ edition.workspace = true
license.workspace = true
[dependencies]
common = { path = "../common" }
gpapi = { path = "../gpapi" }
# Shared dependencies
@@ -32,10 +33,10 @@ html-escape = { version = "0.2.13", optional = true }
webkit2gtk = { version = "2", optional = true }
[target.'cfg(target_os="macos")'.dependencies]
block2 = { version = "0.5", optional = true }
objc2 = { version = "0.5", optional = true }
objc2-foundation = { version = "0.2", optional = true }
objc2-web-kit = { version = "0.2", optional = true }
block2 = { version = "0.6", optional = true }
objc2 = { version = "0.6", optional = true }
objc2-foundation = { version = "0.3", optional = true }
objc2-web-kit = { version = "0.3", optional = true }
[target.'cfg(target_os="windows")'.dependencies]
webview2-com = { version = "0.34", optional = true }
+2 -2
View File
@@ -10,8 +10,8 @@ pub(super) struct AuthServer {
}
impl AuthServer {
pub fn new() -> anyhow::Result<Self> {
let server = Server::http("127.0.0.1:0").map_err(|err| anyhow::anyhow!(err))?;
pub fn new(addr: &str) -> anyhow::Result<Self> {
let server = Server::http(addr).map_err(|err| anyhow::anyhow!(err))?;
let auth_id = Uuid::new_v4().to_string();
Ok(Self { server, auth_id })
+60 -3
View File
@@ -1,8 +1,12 @@
use std::{env::temp_dir, fs};
use gpapi::{auth::SamlAuthData, GP_CALLBACK_PORT_FILENAME};
use common::constants::GP_CALLBACK_PORT_FILENAME;
use gpapi::auth::SamlAuthData;
use log::info;
use tokio::{io::AsyncReadExt, net::TcpListener};
use tokio::{
io::AsyncReadExt,
net::{TcpListener, UdpSocket},
};
use crate::browser::auth_server::AuthServer;
@@ -10,6 +14,7 @@ pub enum Browser<'a> {
Default,
Chrome,
Firefox,
Remote,
Other(&'a str),
}
@@ -19,6 +24,7 @@ impl<'a> Browser<'a> {
"default" => Browser::Default,
"chrome" => Browser::Chrome,
"firefox" => Browser::Firefox,
"remote" => Browser::Remote,
_ => Browser::Other(browser),
}
}
@@ -28,6 +34,7 @@ impl<'a> Browser<'a> {
Browser::Default => "default",
Browser::Chrome => "chrome",
Browser::Firefox => "firefox",
Browser::Remote => "remote",
Browser::Other(browser) => browser,
}
}
@@ -47,7 +54,8 @@ impl<'a> BrowserAuthenticator<'a> {
}
pub async fn authenticate(&self) -> anyhow::Result<SamlAuthData> {
let auth_server = AuthServer::new()?;
let addr = self.determine_addr().await?;
let auth_server = AuthServer::new(&addr)?;
let auth_url = auth_server.auth_url();
let auth_request = self.auth_request.to_string();
@@ -56,6 +64,25 @@ impl<'a> BrowserAuthenticator<'a> {
});
match self.browser {
Browser::Remote => {
info!(
r#"
==== Manual Authentication Required ====
Please open the following URL in your browser:
{}
After completing the authentication, please paste the authentication data back to this terminal.
(The data should start with "globalprotectcallback:...")
Note that the URL is only valid for a single use.
"#,
auth_url
);
return read_auth_data_from_stdin();
}
Browser::Default => {
info!("Launching the default browser...");
webbrowser::open(&auth_url)?;
@@ -71,6 +98,28 @@ impl<'a> BrowserAuthenticator<'a> {
info!("Please continue the authentication process in the default browser");
wait_auth_data().await
}
async fn determine_addr(&self) -> anyhow::Result<String> {
if matches!(self.browser, Browser::Remote) {
let local_ip = detect_local_ip().await?;
Ok(format!("{}:0", local_ip))
} else {
Ok("127.0.0.1:0".to_string())
}
}
}
/// Detect the local IP address by creating a UDP socket and connecting to an external address
async fn detect_local_ip() -> anyhow::Result<String> {
let socket = UdpSocket::bind("0.0.0.0:0").await?;
if let Err(err) = socket.connect("1.1.1.1:80").await {
anyhow::bail!("Failed to connect to external address to determine local IP: {}", err);
}
let local_addr = socket.local_addr()?;
let ip = local_addr.ip().to_string();
info!("Determined local IP address: {}", ip);
Ok(ip.to_string())
}
fn find_browser_path(browser: &Browser) -> String {
@@ -123,3 +172,11 @@ async fn wait_auth_data() -> anyhow::Result<SamlAuthData> {
let auth_data = SamlAuthData::from_gpcallback(&data)?;
Ok(auth_data)
}
fn read_auth_data_from_stdin() -> anyhow::Result<SamlAuthData> {
let mut data = String::new();
std::io::stdin().read_line(&mut data)?;
let auth_data = SamlAuthData::from_gpcallback(data.trim())?;
Ok(auth_data)
}
+2 -1
View File
@@ -103,7 +103,8 @@ impl<'a> WebviewAuthenticator<'a> {
.title("GlobalProtect Login")
.inner_size(900.0, 650.0 + title_bar_height)
.focused(true)
.visible(false)
// when clean is true, the window is expected to be shown because the cookies are cleared
.visible(self.clean)
.center()
.build()?;