aboutsummaryrefslogtreecommitdiff
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
parent80966952450b039b389a866a3d4ece321dde9e14 (diff)
Add a base field to OIDCUser to enable dynamic field extractionHEADmain
-rw-r--r--Cargo.toml3
-rw-r--r--Makefile.toml4
-rw-r--r--src/client/reqwest.rs10
-rw-r--r--src/client/ureq.rs10
-rw-r--r--src/user.rs6
5 files changed, 25 insertions, 8 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 0a4c976..b8a5f1d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,7 +2,7 @@
name = "oidc-rs"
authors = ["Galen Guyer <galen@galenguyer.com"]
description = "A generic OIDC client"
-version = "0.1.0"
+version = "0.1.1"
edition = "2021"
license = "MIT"
repository = "https://github.com/galenguyer/oidc-rs"
@@ -12,6 +12,7 @@ repository = "https://github.com/galenguyer/oidc-rs"
itertools = "0.10.3"
serde = { version = "1.0.139", features = ["derive"] }
cfg-if = "1.0.0"
+serde_json = "1.0.82"
[dependencies.reqwest]
version = "0.11.11"
diff --git a/Makefile.toml b/Makefile.toml
index 7eb9059..5852a98 100644
--- a/Makefile.toml
+++ b/Makefile.toml
@@ -23,7 +23,7 @@ args = ["clippy", "--quiet", "--features=reqwest"]
[tasks.clippy]
clear = true
-run_task = [
+run_task = [
{ name = ["ureq-clippy", "reqwest-clippy"] }
]
@@ -51,4 +51,4 @@ dependencies = [
"check"
]
command = "cargo"
-args = ["publish"]
+args = ["publish", "--features=ureq"]
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);
}