[pdm-devel] [PATCH yew-comp v4 18/21] HttpClient: add helpers to refresh HttpOnly cookies and remove them

Shannon Sterz s.sterz at proxmox.com
Tue Mar 4 13:05:03 CET 2025


the `refresh` function handles a refresh without needing a ticket, the
assumption is that the ticket is handled by an HttpOnly cookie that we
don't have access to.

the `logout` function requests a removal of the ticket by the server
as we cannot remove properly protected cookies from the client-side.

Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
 src/http_client_wasm.rs | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/http_client_wasm.rs b/src/http_client_wasm.rs
index e838e79..22ccbdf 100644
--- a/src/http_client_wasm.rs
+++ b/src/http_client_wasm.rs
@@ -123,6 +123,25 @@ impl HttpClientWasm {
         Ok(login.response(&resp)?)
     }
 
+    pub async fn refresh(&self, username: impl Into<String>) -> Result<TicketResult, Error> {
+        let username = username.into();
+
+        let login = Login::renew_with_cookie("", username);
+        let request = login.request();
+        let request =
+            Self::post_request_builder(&request.url, request.content_type, &request.body)?;
+        let resp = self.fetch_request_text(request).await?;
+
+        Ok(login.response(&resp)?)
+    }
+
+
+    pub async fn logout(&self) -> Result<(), Error> {
+        self.request::<()>(http::Method::DELETE, "/api2/extjs/access/ticket", None)
+            .await?;
+        Ok(())
+    }
+
     pub async fn login_tfa(
         &self,
         challenge: Rc<proxmox_login::SecondFactorChallenge>,
-- 
2.39.5





More information about the pdm-devel mailing list