From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 9559A1FF16F for ; Tue, 14 Oct 2025 15:31:08 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 50B014C10; Tue, 14 Oct 2025 15:31:27 +0200 (CEST) From: Shannon Sterz To: pdm-devel@lists.proxmox.com Date: Tue, 14 Oct 2025 15:30:41 +0200 Message-ID: <20251014133044.337162-6-s.sterz@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251014133044.337162-1-s.sterz@proxmox.com> References: <20251014133044.337162-1-s.sterz@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1760448613700 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.055 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 5/5] utils/login panel: move openid redirection authorization helper to utils X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" this allows users of this crate to check whether url parameters for an openid authorization request are present. allowing for minimal user interaction for completing the login flow. Signed-off-by: Shannon Sterz --- note: this is mostly important for users of this crate that don't show the login component right away (for example, because they want to render a consent screen first). src/login_panel.rs | 34 ++++------------------------------ src/utils.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/login_panel.rs b/src/login_panel.rs index 8926a32..f2ce93f 100644 --- a/src/login_panel.rs +++ b/src/login_panel.rs @@ -18,6 +18,7 @@ use pwt::{prelude::*, AsyncPool}; use proxmox_login::{Authentication, SecondFactorChallenge, Ticket, TicketResult}; use crate::common_api_types::BasicRealmInfo; +use crate::utils; use crate::{tfa::TfaDialog, RealmSelector}; use pwt_macros::builder; @@ -162,35 +163,6 @@ impl ProxmoxLoginPanel { }); } - fn openid_redirection_authorization(ctx: &Context) { - let Ok(query_string) = gloo_utils::window().location().search() else { - return; - }; - - let mut auth = HashMap::new(); - let query_parameters = query_string.split('&'); - - for param in query_parameters { - let mut key_value = param.split('='); - - match (key_value.next(), key_value.next()) { - (Some("?code") | Some("code"), Some(value)) => { - auth.insert("code".to_string(), value.to_string()); - } - (Some("?state") | Some("state"), Some(value)) => { - if let Ok(decoded) = percent_decode(value.as_bytes()).decode_utf8() { - auth.insert("state".to_string(), decoded.to_string()); - } - } - _ => continue, - }; - } - - if auth.contains_key("code") && auth.contains_key("state") { - ctx.link().send_message(Msg::OpenIDAuthorization(auth)); - } - } - fn openid_login(&self, ctx: &Context, mut auth: HashMap) { let link = ctx.link().clone(); let save_username = ctx.props().mobile || *self.save_username; @@ -521,7 +493,9 @@ impl Component for ProxmoxLoginPanel { let save_username = PersistentState::::new("ProxmoxLoginPanelSaveUsername"); let last_username = PersistentState::::new("ProxmoxLoginPanelUsername"); - Self::openid_redirection_authorization(ctx); + if let Some(auth) = utils::openid_redirection_authorization() { + ctx.link().send_message(Msg::OpenIDAuthorization(auth)); + } Self { form_ctx, diff --git a/src/utils.rs b/src/utils.rs index 79b7ad7..1796a0b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::fmt::Display; use std::sync::Mutex; +use percent_encoding::percent_decode; use serde_json::Value; use wasm_bindgen::JsCast; use yew::prelude::*; @@ -462,3 +463,34 @@ pub fn register_pve_tasks() { register_task_description("zfscreate", (tr!("ZFS Storage"), tr!("Create"))); register_task_description("zfsremove", ("ZFS Pool", tr!("Remove"))); } + +pub fn openid_redirection_authorization() -> Option> { + let Ok(query_string) = gloo_utils::window().location().search() else { + return None; + }; + + let mut auth = HashMap::new(); + let query_parameters = query_string.split('&'); + + for param in query_parameters { + let mut key_value = param.split('='); + + match (key_value.next(), key_value.next()) { + (Some("?code") | Some("code"), Some(value)) => { + auth.insert("code".to_string(), value.to_string()); + } + (Some("?state") | Some("state"), Some(value)) => { + if let Ok(decoded) = percent_decode(value.as_bytes()).decode_utf8() { + auth.insert("state".to_string(), decoded.to_string()); + } + } + _ => continue, + }; + } + + if auth.contains_key("code") && auth.contains_key("state") { + return Some(auth); + } + + None +} -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel