From f137b5e52885509968db732ca8686cdb95be22fe Mon Sep 17 00:00:00 2001 From: Shannon Sterz Date: Tue, 4 Mar 2025 15:42:37 +0100 Subject: [PATCH] login: make password optional when creating Login requests in certain context (for example, the browser), no password needs to be provided when using HttpOnly cookies as they are handle by said context. so make renewing ticket with password optional and add a new helper function that does not require a password. Signed-off-by: Shannon Sterz --- proxmox-login/src/lib.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/proxmox-login/src/lib.rs b/proxmox-login/src/lib.rs index d7798b62..3b3558d0 100644 --- a/proxmox-login/src/lib.rs +++ b/proxmox-login/src/lib.rs @@ -50,7 +50,7 @@ pub struct Request { pub struct Login { api_url: String, userid: String, - password: String, + password: Option, pve_compat: bool, } @@ -96,7 +96,18 @@ impl Login { api_url: normalize_url(api_url.into()), pve_compat: ticket.product() == "PVE", userid: ticket.userid().to_string(), - password: ticket.into(), + password: Some(ticket.into()), + } + } + + /// Prepare a request with the assumption that the context handles the ticket (usually in a + /// browser via an HttpOnly cookie). + pub fn renew_with_cookie(api_url: impl Into, userid: impl Into) -> Self { + Self { + api_url: normalize_url(api_url.into()), + pve_compat: false, + userid: userid.into(), + password: None, } } @@ -109,7 +120,7 @@ impl Login { Self { api_url: normalize_url(api_url.into()), userid: userid.into(), - password: password.into(), + password: Some(password.into()), pve_compat: false, } } @@ -129,7 +140,7 @@ impl Login { let request = api::CreateTicket { new_format: self.pve_compat.then_some(true), username: self.userid.clone(), - password: Some(self.password.clone()), + password: self.password.clone(), ..Default::default() };