public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-openid-rs v2 3/6] new helper verify_authorization_code_simple()
Date: Fri,  6 Aug 2021 13:57:41 +0200	[thread overview]
Message-ID: <20210806115744.1959420-6-dietmar@proxmox.com> (raw)
In-Reply-To: <20210806115744.1959420-1-dietmar@proxmox.com>

Simply return data as serde_json::Value.
---
 src/lib.rs | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/lib.rs b/src/lib.rs
index abcd06e..5d8b758 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,6 +2,7 @@ use std::path::Path;
 
 use anyhow::{format_err, Error};
 use serde::{Deserialize, Serialize};
+use serde_json::Value;
 
 mod http_client;
 pub use http_client::http_client;
@@ -39,7 +40,7 @@ use openidconnect::{
 
 /// Stores Additional Claims into a serde_json::Value;
 #[derive(Debug, Deserialize, Serialize)]
-pub struct GenericClaims(serde_json::Value);
+pub struct GenericClaims(Value);
 impl AdditionalClaims for GenericClaims {}
 
 pub type GenericUserInfoClaims = UserInfoClaims<GenericClaims, CoreGenderClaim>;
@@ -196,4 +197,29 @@ impl OpenIdAuthenticator {
 
         Ok((id_token_claims.clone(), userinfo_claims))
     }
+
+    /// Like verify_authorization_code(), but returns claims as serde_json::Value
+    pub fn verify_authorization_code_simple(
+        &self,
+        code: &str,
+        private_auth_state: &PrivateAuthState,
+    ) -> Result<Value, Error> {
+
+        let (id_token_claims, userinfo_claims) = self.verify_authorization_code(&code, &private_auth_state)?;
+
+        let mut data = serde_json::to_value(id_token_claims)?;
+
+        let data2 = serde_json::to_value(userinfo_claims)?;
+
+        if let Some(map) = data2.as_object() {
+            for (key, value) in map {
+                if data[key] != Value::Null {
+                    continue; // already set
+                }
+                data[key] = value.clone();
+            }
+        }
+
+        Ok(data)
+    }
 }
-- 
2.30.2





  parent reply	other threads:[~2021-08-06 11:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06 11:57 [pbs-devel] [PATCH proxmox-openid-rs v2 1/6] allow to configure used scopes Dietmar Maurer
2021-08-06 11:57 ` [pbs-devel] [PATCH pve-rs] depend on proxmox-openid 0.7.0, bump version to 0.3.0 Dietmar Maurer
2021-08-06 11:57 ` [pbs-devel] [PATCH proxmox-backup v2] openid: allow to configure scopes, prompt, ACRs and arbitrary username-claim values Dietmar Maurer
2021-08-06 11:57 ` [pbs-devel] [PATCH pve-access-control] openid: support " Dietmar Maurer
2021-08-06 11:57 ` [pbs-devel] [PATCH proxmox-openid-rs v2 2/6] also return data from UserInfo endpoint Dietmar Maurer
2021-08-06 11:57 ` Dietmar Maurer [this message]
2021-08-06 11:57 ` [pbs-devel] [PATCH proxmox-openid-rs v2 4/6] allow to configure prompt behaviour Dietmar Maurer
2021-08-06 11:57 ` [pbs-devel] [PATCH proxmox-openid-rs v2 5/6] allow to configure acr values Dietmar Maurer
2021-08-06 11:57 ` [pbs-devel] [PATCH proxmox-openid-rs v2 6/6] bump version to 0.7.0-1 Dietmar Maurer

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=20210806115744.1959420-6-dietmar@proxmox.com \
    --to=dietmar@proxmox.com \
    --cc=pbs-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal