aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2022-07-18 16:44:12 -0400
committerGalen Guyer <galen@galenguyer.com>2022-07-18 16:45:10 -0400
commit430fc85456711cbb1e93350f1043b45aa5fed5bc (patch)
tree6be364e1b1f5237b4b254c909d775dd333faeec9 /src
parent80966952450b039b389a866a3d4ece321dde9e14 (diff)
Add a base field to OIDCUser to enable dynamic field extractionHEADmain
Diffstat (limited to 'src')
-rw-r--r--src/client/reqwest.rs10
-rw-r--r--src/client/ureq.rs10
-rw-r--r--src/user.rs6
3 files changed, 21 insertions, 5 deletions
diff --git a/src/client/reqwest.rs b/src/client/reqwest.rs
index b75458e..c9283f0 100644
--- a/src/client/reqwest.rs
+++ b/src/client/reqwest.rs
@@ -44,8 +44,14 @@ impl OIDCClient {
match res {
Ok(response) => {
if response.status().is_success() {
- match response.json::<OIDCUser>().await {
- Ok(user) => Ok(user),
+ match response.json::<serde_json::Value>().await {
+ Ok(value) => match serde_json::from_value::<OIDCUser>(value.clone()) {
+ Ok(user) => Ok(OIDCUser {
+ base: value,
+ ..user
+ }),
+ Err(_e) => Err(OIDCError::Unknown),
+ },
Err(e) => Err(OIDCError::ReqwestError(Box::new(e))),
}
} else if response.status().is_client_error() {
diff --git a/src/client/ureq.rs b/src/client/ureq.rs
index f6d59d4..d52d664 100644
--- a/src/client/ureq.rs
+++ b/src/client/ureq.rs
@@ -43,8 +43,14 @@ impl OIDCClient {
match res {
Ok(response) => {
if response.status() >= 200 && response.status() <= 300 {
- match response.into_json::<OIDCUser>() {
- Ok(user) => Ok(user),
+ match response.into_json::<serde_json::Value>() {
+ Ok(value) => match serde_json::from_value::<OIDCUser>(value.clone()) {
+ Ok(user) => Ok(OIDCUser {
+ base: value,
+ ..user
+ }),
+ Err(_e) => Err(OIDCError::Unknown),
+ },
// TODO: need a better error here... but ureq and reqwest do different types
Err(_e) => Err(OIDCError::Unknown),
}
diff --git a/src/user.rs b/src/user.rs
index c6283e4..636056c 100644
--- a/src/user.rs
+++ b/src/user.rs
@@ -10,7 +10,9 @@ pub struct OIDCUser {
pub preferred_username: String,
/// Any groups the user is in
pub groups: Box<[String]>,
- // TODO: A variable list of any other attributes we're given
+ /// The base object we're given by OIDC
+ #[serde(skip)]
+ pub base: serde_json::Value,
}
impl OIDCUser {
@@ -28,6 +30,7 @@ mod tests {
name: Some(String::from("Testy McTestyFace")),
preferred_username: String::from("test"),
groups: Box::new([String::from("member")]),
+ base: serde_json::json!({}),
};
assert_eq!(user.has_group("member"), true);
}
@@ -38,6 +41,7 @@ mod tests {
name: Some(String::from("Testy McTestyFace")),
preferred_username: String::from("test"),
groups: Box::new([]),
+ base: serde_json::json!({}),
};
assert_eq!(user.has_group("missing"), false);
}