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_header(&self, key: &str) -> Option<String>;
|
||||||
|
|
||||||
fn get_body(&self, cb: Box<dyn FnOnce(anyhow::Result<Option<Cow<'_, str>>>) + 'static>);
|
fn get_body(&self, cb: Box<dyn FnOnce(anyhow::Result<Option<Cow<'_, str>>>) + 'static>);
|
||||||
}
|
|
||||||
|
|
||||||
fn is_acs_endpoint(auth_response: &impl ResponseReader) -> bool {
|
fn is_acs_endpoint(&self) -> bool {
|
||||||
auth_response.url().map_or(false, |url| url.ends_with("/SAML20/SP/ACS"))
|
self.url().map_or(false, |url| url.ends_with("/SAML20/SP/ACS"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_auth_data<F>(auth_response: &impl ResponseReader, cb: F)
|
pub fn read_auth_data<F>(auth_response: &impl ResponseReader, cb: F)
|
||||||
@ -36,7 +36,7 @@ where
|
|||||||
Err(header_err) => {
|
Err(header_err) => {
|
||||||
info!("Failed to read auth data from headers: {}", 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| {
|
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
|
// 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| {
|
let auth_result = auth_result.map_err(move |e| {
|
||||||
|
@ -7,30 +7,24 @@ use wry::WebViewExtUnix;
|
|||||||
|
|
||||||
use crate::webview::auth_messenger::AuthError;
|
use crate::webview::auth_messenger::AuthError;
|
||||||
|
|
||||||
pub struct AuthResponse {
|
use super::response_reader::ResponseReader;
|
||||||
web_resource: WebResource,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AuthResponse {
|
impl ResponseReader for WebResource {
|
||||||
pub fn url(&self) -> Option<String> {
|
fn url(&self) -> Option<String> {
|
||||||
self.web_resource.uri().map(GString::into)
|
self.uri().map(GString::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_header(&self, key: &str) -> Option<String> {
|
fn get_header(&self, key: &str) -> Option<String> {
|
||||||
self
|
self
|
||||||
.web_resource
|
|
||||||
.response()
|
.response()
|
||||||
.and_then(|response| response.http_headers())
|
.and_then(|response| response.http_headers())
|
||||||
.and_then(|headers| headers.one(key))
|
.and_then(|headers| headers.one(key))
|
||||||
.map(GString::into)
|
.map(GString::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_body<F>(&self, cb: F)
|
fn get_body(&self, cb: Box<dyn FnOnce(anyhow::Result<Option<Cow<'_, str>>>) + 'static>) {
|
||||||
where
|
|
||||||
F: FnOnce(anyhow::Result<Option<Cow<'_, str>>>) + 'static,
|
|
||||||
{
|
|
||||||
let cancellable = Cancellable::NONE;
|
let cancellable = Cancellable::NONE;
|
||||||
self.web_resource.data(cancellable, move |data| {
|
self.data(cancellable, move |data| {
|
||||||
let body = data
|
let body = data
|
||||||
.map_err(|e| anyhow::anyhow!(e))
|
.map_err(|e| anyhow::anyhow!(e))
|
||||||
.map(|data| String::from_utf8_lossy(&data).into_owned())
|
.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)
|
pub fn connect_webview_response<F>(wv: &wry::WebView, cb: F)
|
||||||
where
|
where
|
||||||
F: Fn(anyhow::Result<AuthResponse, AuthError>) + 'static,
|
F: Fn(anyhow::Result<WebResource, AuthError>) + 'static,
|
||||||
{
|
{
|
||||||
let wv = wv.webview();
|
let wv = wv.webview();
|
||||||
let cb = Arc::new(cb);
|
let cb = Arc::new(cb);
|
||||||
@ -71,9 +65,7 @@ where
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let response = AuthResponse { web_resource };
|
cb_clone(Ok(web_resource));
|
||||||
|
|
||||||
cb_clone(Ok(response));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
wv.connect_load_failed_with_tls_errors(move |_wv, uri, cert, err| {
|
wv.connect_load_failed_with_tls_errors(move |_wv, uri, cert, err| {
|
||||||
|
Loading…
Reference in New Issue
Block a user