all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Shannon Sterz <s.sterz@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH yew-comp v2 5/5] utils/login panel: move openid redirection authorization helper to utils
Date: Fri, 17 Oct 2025 15:58:00 +0200	[thread overview]
Message-ID: <20251017135802.363955-7-s.sterz@proxmox.com> (raw)
In-Reply-To: <20251017135802.363955-2-s.sterz@proxmox.com>

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 <s.sterz@proxmox.com>
---
 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 9d1d5d6..75721f5 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<Self>) {
-        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<Self>, mut auth: HashMap<String, String>) {
         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::<bool>::new("ProxmoxLoginPanelSaveUsername");
         let last_username = PersistentState::<String>::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 3dfc696..f1ea984 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<HashMap<String, String>> {
+    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


  parent reply	other threads:[~2025-10-17 13:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-17 13:57 [pdm-devel] [PATCH datacenter-manager/yew-comp v2 0/8] openid support for PDM Shannon Sterz
2025-10-17 13:57 ` [pdm-devel] [PATCH yew-comp v2 1/5] login_panel/realm_selector: use default realm provided by api Shannon Sterz
2025-10-22 17:03   ` [pdm-devel] applied: " Thomas Lamprecht
2025-10-17 13:57 ` [pdm-devel] [PATCH yew-comp v2 2/5] login_panel/realm_selector: add support for openid realm logins Shannon Sterz
2025-10-22 17:03   ` [pdm-devel] applied: " Thomas Lamprecht
2025-10-17 13:57 ` [pdm-devel] [PATCH yew-comp v2 3/5] auth view: add openid icon to openid menu option Shannon Sterz
2025-10-22 17:03   ` [pdm-devel] applied: " Thomas Lamprecht
2025-10-17 13:57 ` [pdm-devel] [PATCH yew-comp v2 4/5] auth edit openid: add a default realm checkbox Shannon Sterz
2025-10-22 17:03   ` [pdm-devel] applied: " Thomas Lamprecht
2025-10-17 13:58 ` Shannon Sterz [this message]
2025-10-22 17:03   ` [pdm-devel] applied: [PATCH yew-comp v2 5/5] utils/login panel: move openid redirection authorization helper to utils Thomas Lamprecht
2025-10-17 13:58 ` [pdm-devel] [PATCH datacenter-manager v2 1/3] api-types: add default field to openid realm config Shannon Sterz
2025-10-22 17:22   ` [pdm-devel] applied: " Thomas Lamprecht
2025-10-17 13:58 ` [pdm-devel] [PATCH datacenter-manager v2 2/3] server: api: add support for adding openid realms and openid logins Shannon Sterz
2025-10-22 17:22   ` [pdm-devel] applied: " Thomas Lamprecht
2025-10-17 13:58 ` [pdm-devel] [PATCH datacenter-manager v2 3/3] ui: enable openid realms in realm panel Shannon Sterz
2025-10-22 17:22   ` [pdm-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251017135802.363955-7-s.sterz@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal