mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
feat: gpauth support macos
This commit is contained in:
parent
03d0d3e08f
commit
171386d93c
@ -17,10 +17,10 @@ pub trait ResponseReader {
|
||||
fn get_header(&self, key: &str) -> Option<String>;
|
||||
|
||||
fn get_body(&self, cb: Box<dyn FnOnce(anyhow::Result<Option<Cow<'_, str>>>) + 'static>);
|
||||
}
|
||||
|
||||
fn is_acs_endpoint(auth_response: &impl ResponseReader) -> bool {
|
||||
auth_response.url().map_or(false, |url| url.ends_with("/SAML20/SP/ACS"))
|
||||
fn is_acs_endpoint(&self) -> bool {
|
||||
self.url().map_or(false, |url| url.ends_with("/SAML20/SP/ACS"))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_auth_data<F>(auth_response: &impl ResponseReader, cb: F)
|
||||
@ -36,7 +36,7 @@ where
|
||||
Err(header_err) => {
|
||||
info!("Failed to read auth data from headers: {}", header_err);
|
||||
|
||||
let is_acs_endpoint = is_acs_endpoint(auth_response);
|
||||
let is_acs_endpoint = auth_response.is_acs_endpoint();
|
||||
read_from_body(auth_response, move |auth_result| {
|
||||
// If the endpoint is `/SAML20/SP/ACS` and no auth data found in body, it should be considered as invalid
|
||||
let auth_result = auth_result.map_err(move |e| {
|
||||
|
@ -7,30 +7,24 @@ use wry::WebViewExtUnix;
|
||||
|
||||
use crate::webview::auth_messenger::AuthError;
|
||||
|
||||
pub struct AuthResponse {
|
||||
web_resource: WebResource,
|
||||
}
|
||||
use super::response_reader::ResponseReader;
|
||||
|
||||
impl AuthResponse {
|
||||
pub fn url(&self) -> Option<String> {
|
||||
self.web_resource.uri().map(GString::into)
|
||||
impl ResponseReader for WebResource {
|
||||
fn url(&self) -> Option<String> {
|
||||
self.uri().map(GString::into)
|
||||
}
|
||||
|
||||
pub fn get_header(&self, key: &str) -> Option<String> {
|
||||
fn get_header(&self, key: &str) -> Option<String> {
|
||||
self
|
||||
.web_resource
|
||||
.response()
|
||||
.and_then(|response| response.http_headers())
|
||||
.and_then(|headers| headers.one(key))
|
||||
.map(GString::into)
|
||||
}
|
||||
|
||||
pub fn get_body<F>(&self, cb: F)
|
||||
where
|
||||
F: FnOnce(anyhow::Result<Option<Cow<'_, str>>>) + 'static,
|
||||
{
|
||||
fn get_body(&self, cb: Box<dyn FnOnce(anyhow::Result<Option<Cow<'_, str>>>) + 'static>) {
|
||||
let cancellable = Cancellable::NONE;
|
||||
self.web_resource.data(cancellable, move |data| {
|
||||
self.data(cancellable, move |data| {
|
||||
let body = data
|
||||
.map_err(|e| anyhow::anyhow!(e))
|
||||
.map(|data| String::from_utf8_lossy(&data).into_owned())
|
||||
@ -43,7 +37,7 @@ impl AuthResponse {
|
||||
|
||||
pub fn connect_webview_response<F>(wv: &wry::WebView, cb: F)
|
||||
where
|
||||
F: Fn(anyhow::Result<AuthResponse, AuthError>) + 'static,
|
||||
F: Fn(anyhow::Result<WebResource, AuthError>) + 'static,
|
||||
{
|
||||
let wv = wv.webview();
|
||||
let cb = Arc::new(cb);
|
||||
@ -71,9 +65,7 @@ where
|
||||
return;
|
||||
}
|
||||
|
||||
let response = AuthResponse { web_resource };
|
||||
|
||||
cb_clone(Ok(response));
|
||||
cb_clone(Ok(web_resource));
|
||||
});
|
||||
|
||||
wv.connect_load_failed_with_tls_errors(move |_wv, uri, cert, err| {
|
||||
|
Loading…
Reference in New Issue
Block a user