mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-05-20 07:26:58 -04:00
Restore the browser auth, related #360
This commit is contained in:
34
crates/gpapi/src/process/browser_authenticator.rs
Normal file
34
crates/gpapi/src/process/browser_authenticator.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use std::{env::temp_dir, io::Write};
|
||||
|
||||
pub struct BrowserAuthenticator<'a> {
|
||||
auth_request: &'a str,
|
||||
}
|
||||
|
||||
impl BrowserAuthenticator<'_> {
|
||||
pub fn new(auth_request: &str) -> BrowserAuthenticator {
|
||||
BrowserAuthenticator { auth_request }
|
||||
}
|
||||
|
||||
pub fn authenticate(&self) -> anyhow::Result<()> {
|
||||
if self.auth_request.starts_with("http") {
|
||||
open::that_detached(self.auth_request)?;
|
||||
} else {
|
||||
let html_file = temp_dir().join("gpauth.html");
|
||||
let mut file = std::fs::File::create(&html_file)?;
|
||||
|
||||
file.write_all(self.auth_request.as_bytes())?;
|
||||
|
||||
open::that_detached(html_file)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for BrowserAuthenticator<'_> {
|
||||
fn drop(&mut self) {
|
||||
// Cleanup the temporary file
|
||||
let html_file = temp_dir().join("gpauth.html");
|
||||
let _ = std::fs::remove_file(html_file);
|
||||
}
|
||||
}
|
@@ -2,6 +2,8 @@ pub(crate) mod command_traits;
|
||||
pub(crate) mod gui_helper_launcher;
|
||||
|
||||
pub mod auth_launcher;
|
||||
#[cfg(feature = "browser-auth")]
|
||||
pub mod browser_authenticator;
|
||||
pub mod gui_launcher;
|
||||
pub mod hip_launcher;
|
||||
pub mod service_launcher;
|
||||
|
Reference in New Issue
Block a user