From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pdm-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id F19171FF1C1
	for <inbox@lore.proxmox.com>; Tue,  4 Mar 2025 13:05:56 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 851CF1E016;
	Tue,  4 Mar 2025 13:05:53 +0100 (CET)
From: Shannon Sterz <s.sterz@proxmox.com>
To: pdm-devel@lists.proxmox.com
Date: Tue,  4 Mar 2025 13:05:03 +0100
Message-Id: <20250304120506.135617-19-s.sterz@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250304120506.135617-1-s.sterz@proxmox.com>
References: <20250304120506.135617-1-s.sterz@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.019 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pdm-devel] [PATCH yew-comp v4 18/21] HttpClient: add helpers to
 refresh HttpOnly cookies and remove them
X-BeenThere: pdm-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Datacenter Manager development discussion
 <pdm-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, 
 <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/>
List-Post: <mailto:pdm-devel@lists.proxmox.com>
List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, 
 <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Datacenter Manager development discussion
 <pdm-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pdm-devel-bounces@lists.proxmox.com
Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com>

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@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



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel