diff --git a/proxmox-rest-server/examples/minimal-rest-server.rs b/proxmox-rest-server/examples/minimal-rest-server.rs index 22477039..8954ce76 100644 --- a/proxmox-rest-server/examples/minimal-rest-server.rs +++ b/proxmox-rest-server/examples/minimal-rest-server.rs @@ -1,5 +1,7 @@ use std::sync::{Arc, Mutex}; use std::collections::HashMap; +use std::future::Future; +use std::pin::Pin; use anyhow::{bail, format_err, Error}; use lazy_static::lazy_static; @@ -26,15 +28,17 @@ impl UserInformation for DummyUserInfo { struct DummyAuth; impl ApiAuth for DummyAuth { - fn check_auth( - &self, - _headers: &http::HeaderMap, - _method: &hyper::Method, - ) -> Result<(String, Box), AuthError> { - // get some global/cached userinfo - let userinfo = DummyUserInfo; - // Do some user checks, e.g. cookie/csrf - Ok(("User".to_string(), Box::new(userinfo))) + fn check_auth<'a>( + &'a self, + _headers: &'a http::HeaderMap, + _method: &'a hyper::Method, + ) -> Pin), AuthError>> + Send + 'a>> { + Box::pin(async move { + // get some global/cached userinfo + let userinfo: Box = Box::new(DummyUserInfo); + // Do some user checks, e.g. cookie/csrf + Ok(("User".to_string(), userinfo)) + }) } } diff --git a/proxmox-rest-server/src/lib.rs b/proxmox-rest-server/src/lib.rs index fe392775..bb29295c 100644 --- a/proxmox-rest-server/src/lib.rs +++ b/proxmox-rest-server/src/lib.rs @@ -16,6 +16,8 @@ //! * generic interface to authenticate user use std::sync::atomic::{Ordering, AtomicBool}; +use std::future::Future; +use std::pin::Pin; use anyhow::{bail, format_err, Error}; use nix::unistd::Pid; @@ -74,11 +76,11 @@ pub trait ApiAuth { /// /// If credenthials are valid, returns the username and a /// [UserInformation] object to query additional user data. - fn check_auth( - &self, - headers: &http::HeaderMap, - method: &hyper::Method, - ) -> Result<(String, Box), AuthError>; + fn check_auth<'a>( + &'a self, + headers: &'a http::HeaderMap, + method: &'a hyper::Method, + ) -> Pin), AuthError>> + Send + 'a>>; } lazy_static::lazy_static!{ diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs index e65e5d6b..80ab0461 100644 --- a/proxmox-rest-server/src/rest.rs +++ b/proxmox-rest-server/src/rest.rs @@ -654,7 +654,7 @@ async fn handle_request( let mut user_info: Box = Box::new(EmptyUserInformation {}); if auth_required { - match auth.check_auth(&parts.headers, &method) { + match auth.check_auth(&parts.headers, &method).await { Ok((authid, info)) => { rpcenv.set_auth_id(Some(authid)); user_info = info; @@ -726,7 +726,7 @@ async fn handle_request( if comp_len == 0 { let language = extract_lang_header(&parts.headers); - match auth.check_auth(&parts.headers, &method) { + match auth.check_auth(&parts.headers, &method).await { Ok((auth_id, _user_info)) => { return Ok(api.get_index(Some(auth_id), language, parts)); }