From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-openid-rs 2/5] also return data from UserInfo endpoint
Date: Fri, 6 Aug 2021 09:17:06 +0200 [thread overview]
Message-ID: <20210806071709.1796794-4-dietmar@proxmox.com> (raw)
In-Reply-To: <20210806071709.1796794-1-dietmar@proxmox.com>
---
src/lib.rs | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/lib.rs b/src/lib.rs
index dcd08dd..abcd06e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -20,6 +20,7 @@ use openidconnect::{
CoreAuthenticationFlow,
CoreAuthDisplay,
CoreAuthPrompt,
+ CoreGenderClaim,
},
PkceCodeChallenge,
PkceCodeVerifier,
@@ -32,9 +33,18 @@ use openidconnect::{
OAuth2TokenResponse,
RedirectUrl,
Scope,
+ UserInfoClaims,
+ AdditionalClaims,
};
-#[derive(Debug, Deserialize, Serialize, Clone)]
+/// Stores Additional Claims into a serde_json::Value;
+#[derive(Debug, Deserialize, Serialize)]
+pub struct GenericClaims(serde_json::Value);
+impl AdditionalClaims for GenericClaims {}
+
+pub type GenericUserInfoClaims = UserInfoClaims<GenericClaims, CoreGenderClaim>;
+
+ #[derive(Debug, Deserialize, Serialize, Clone)]
pub struct OpenIdConfig {
pub issuer_url: String,
pub client_id: String,
@@ -161,7 +171,7 @@ impl OpenIdAuthenticator {
&self,
code: &str,
private_auth_state: &PrivateAuthState,
- ) -> Result<CoreIdTokenClaims, Error> {
+ ) -> Result<(CoreIdTokenClaims, GenericUserInfoClaims), Error> {
let code = AuthorizationCode::new(code.to_string());
// Exchange the code with a token.
@@ -179,6 +189,11 @@ impl OpenIdAuthenticator {
.claims(&id_token_verifier, &private_auth_state.nonce)
.map_err(|err| format_err!("Failed to verify ID token: {}", err))?;
- Ok(id_token_claims.clone())
+ let userinfo_claims: GenericUserInfoClaims = self.client
+ .user_info(token_response.access_token().to_owned(), None)?
+ .request(http_client)
+ .map_err(|err| format_err!("Failed to contact userinfo endpoint: {}", err))?;
+
+ Ok((id_token_claims.clone(), userinfo_claims))
}
}
--
2.30.2
next prev parent reply other threads:[~2021-08-06 7:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-06 7:17 [pbs-devel] [PATCH proxmox-openid-rs 1/5] allow to configure used scopes Dietmar Maurer
2021-08-06 7:17 ` [pbs-devel] [PATCH pve-rs] depend on proxmox-openid 0.7.0, bump version to 0.3.0 Dietmar Maurer
2021-08-06 7:17 ` [pbs-devel] [PATCH proxmox-backup] openid: allow to configure scopes, prompt and arbitrary username-claim values Dietmar Maurer
2021-08-06 7:17 ` Dietmar Maurer [this message]
2021-08-06 7:17 ` [pbs-devel] [PATCH proxmox-openid-rs 3/5] new helper verify_authorization_code_simple() Dietmar Maurer
2021-08-06 7:17 ` [pbs-devel] [PATCH proxmox-openid-rs 4/5] allow to configure prompt behaviour Dietmar Maurer
2021-08-06 7:17 ` [pbs-devel] [PATCH proxmox-openid-rs 5/5] 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=20210806071709.1796794-4-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 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.