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 F0F6D1FF15F for ; Mon, 16 Dec 2024 05:16:17 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 95A3140B6; Mon, 16 Dec 2024 05:16:23 +0100 (CET) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734322543; x=1734927343; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ify1j9sNGsdTFWxkumn6B9Q/IvNIYNxLsbbRVscp7dU=; b=uu4oeD/jSiG/ctEu3Nd8pZfqoXb6GNThH4FzvjpSdf0dJpTFS7PC/Lsy7oOEWxb/fC r+WjOC17lu2fgZRTJFoIgRMg9D7IjI83bgrwZGYV70iqMLLCZRIfaGc5F4NpYgMgPZQg ee/wio1rBRQaGvBW5/P77V6TMsjFXjd04/GvJAIBM5JgqlWAE8nzidFKIEMkCVtlS9VU MTtTrX2GKE/tk4XuPSX2xBUnLJLmvk+aBLsNRRyJBDV8aYITZU++3t9dewcHdly5Xelp 1NNfLyx1Uavbw27G++rlBTYH3xpF5J81s3qWFP4DoJu1LESG3J6u8f/BFlaZgTlSE1ty lphQ== X-Gm-Message-State: AOJu0Yw0KSvTlhz+DXyCciGHCuhs2MTMikB774sfQi2rGMIPGJW1myYo pVktjKI9KmDEoSpljQHl3rOk25W/yG8+3lxEM6oc8DXa5MsYM51TbcbB0A== X-Gm-Gg: ASbGncvJ7G2iFDb4LJiS9zciwlIHKiDrL0+bg5CMLXAkeGdRZl+/OzsL7Ew5zFpfjbb tfUnrs/3+0p+svodAeG1iKnX74bscAKMAdtxeT5Mk25tEyupe3rFqhbQz2U4F30Hpnn+ndmz78V akUWjF+D+BB08K/pteKU+BkfFhTemL7Mq2Ul2jDNzBgYRsBwoiqwxBvWns7+M7ISJBT/WF0pJAU EjVOELhSheTc7FHanY3R+F/oroF203T//Uy5OByOLMgtYnSRR7JatwLqw93dJCEy1y4+mu5YsLJ LZGYtAdqzQqmeN7njCkTh98kYgpV1lSaQ5ILQzVtlgkta1F3RozCbG+DxLhsX0lG6fQaKA== X-Google-Smtp-Source: AGHT+IF9yFDO6e3NBWaJRpu/8LNk6cqxW0Hwb7VcO5SLU8FZ1AkvT9wlell+9j8bPsCQnzcgI/Bw2w== X-Received: by 2002:a05:6902:330d:b0:e44:82ef:3973 with SMTP id 3f1490d57ef6-e4482ef4139mr5374374276.4.1734322543031; Sun, 15 Dec 2024 20:15:43 -0800 (PST) From: Thomas Skinner To: pve-devel@lists.proxmox.com Date: Sun, 15 Dec 2024 22:14:28 -0600 Message-Id: <20241216041428.1184350-6-thomas@atskinner.net> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241216041428.1184350-1-thomas@atskinner.net> References: <20241216041428.1184350-1-thomas@atskinner.net> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.449 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 FREEMAIL_FORGED_FROMDOMAIN 0.001 2nd level domains in From and EnvelopeFrom freemail headers are different FREEMAIL_FROM 0.001 Sender email is commonly abused enduser mail provider HEADER_FROM_DIFFERENT_DOMAINS 0.248 From and EnvelopeFrom 2nd level mail domains are different KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_MSPIKE_H2 -1.13 Average reputation (+2) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox v2 5/5] fix #4234: openid: add library functions for optional userinfo endpoint X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Cc: Thomas Skinner Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Signed-off-by: Thomas Skinner --- proxmox-openid/src/lib.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/proxmox-openid/src/lib.rs b/proxmox-openid/src/lib.rs index fe65fded..87be1c8a 100644 --- a/proxmox-openid/src/lib.rs +++ b/proxmox-openid/src/lib.rs @@ -31,6 +31,7 @@ use openidconnect::{ PkceCodeVerifier, RedirectUrl, Scope, + StandardClaims, UserInfoClaims, }; @@ -195,6 +196,15 @@ impl OpenIdAuthenticator { &self, code: &str, private_auth_state: &PrivateAuthState, + ) -> Result<(CoreIdTokenClaims, GenericUserInfoClaims), Error> { + self.verify_authorization_code_userinfo(code, private_auth_state, true) + } + + pub fn verify_authorization_code_userinfo( + &self, + code: &str, + private_auth_state: &PrivateAuthState, + disable_userinfo: bool, ) -> Result<(CoreIdTokenClaims, GenericUserInfoClaims), Error> { let code = AuthorizationCode::new(code.to_string()); // Exchange the code with a token. @@ -213,6 +223,14 @@ impl OpenIdAuthenticator { .claims(&id_token_verifier, &private_auth_state.nonce) .map_err(|err| format_err!("Failed to verify ID token: {}", err))?; + if disable_userinfo { + let empty_userinfo_claims = UserInfoClaims::new( + StandardClaims::new(id_token_claims.subject().clone()), + GenericClaims(Value::Null), + ); + return Ok((id_token_claims.clone(), empty_userinfo_claims)); + } + let userinfo_claims: GenericUserInfoClaims = self .client .user_info(token_response.access_token().to_owned(), None)? @@ -227,9 +245,19 @@ impl OpenIdAuthenticator { &self, code: &str, private_auth_state: &PrivateAuthState, + ) -> Result { + self.verify_authorization_code_simple_userinfo(code, private_auth_state, true) + } + + /// Like verify_authorization_code_simple_userinfo(), but returns claims as serde_json::Value + pub fn verify_authorization_code_simple_userinfo( + &self, + code: &str, + private_auth_state: &PrivateAuthState, + disable_userinfo: bool, ) -> Result { let (id_token_claims, userinfo_claims) = - self.verify_authorization_code(code, private_auth_state)?; + self.verify_authorization_code_userinfo(code, private_auth_state, disable_userinfo)?; let mut data = serde_json::to_value(id_token_claims)?; -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel