From 5d4832b12e797e7f4b848b7c0b7f201a4c6a18fd Mon Sep 17 00:00:00 2001 From: Philip Cristiano Date: Tue, 19 Mar 2024 12:49:32 -0400 Subject: [PATCH] feat: display scopes and groups for user --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- oidc.toml.example | 1 - src/main.rs | 35 ++++++++++++++++++++++++++++++++--- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5442d6a..8f95931 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2299,9 +2299,9 @@ dependencies = [ [[package]] name = "service_conventions" -version = "0.0.7" +version = "0.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dd490018e4d6cead8f3df9c4f99efa47940495cf0ca0dbbd401cf5c03eea14d" +checksum = "8d5241a9f6b6afcb6c3c04307580291badfee689452dffbf719866127e0aec86" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index b5c7da6..6f40d98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,8 @@ once_cell = "1.19.0" openidconnect = "3.5.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -service_conventions = { version = "0.0.7", features = ["tracing", "oidc"]} -#service_conventions = { git = "https://github.com/philipcristiano/rust_service_conventions.git", branch = "default-oidc", features = ["tracing", "oidc"]} +service_conventions = { version = "0.0.8", features = ["tracing", "oidc"]} +#service_conventions = { git = "https://github.com/philipcristiano/rust_service_conventions.git", branch = "groups", features = ["tracing", "oidc"]} tokio = { version = "1.36.0", features = ["full"] } toml = "0.8.12" tonic = { version = "0.11.0", features = ["tls", "tls-roots"] } diff --git a/oidc.toml.example b/oidc.toml.example index a02eb8b..9de4860 100644 --- a/oidc.toml.example +++ b/oidc.toml.example @@ -3,4 +3,3 @@ issuer_url = "https://kanidm.home.cristiano.cloud/oauth2/openid/hello_idc" redirect_url = "https://hello_idc.home.cristiano.cloud/oidc/login_auth" client_id = "client_id" client_secret = "foo" -post_auth_path = "/user" diff --git a/src/main.rs b/src/main.rs index 598dc6d..3fd1bb4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,8 +28,25 @@ pub struct Args { #[derive(Clone, Debug, Deserialize)] struct AppConfig { + auth: service_conventions::oidc::OIDCConfig, +} +#[derive(Clone, Debug)] +struct AppState { auth: service_conventions::oidc::AuthConfig, } + +impl From for AppState { + fn from(item: AppConfig) -> Self { + let auth_config = service_conventions::oidc::AuthConfig{ + oidc_config: item.auth, + post_auth_path: "/user".to_string(), + scopes: vec!("profile".to_string(), "email".to_string()) + }; + AppState { + auth: auth_config + } + } +} use tower_http::trace::{self, TraceLayer}; use tracing::Level; @@ -46,15 +63,15 @@ async fn main() { let app_config: AppConfig = toml::from_str(&config_file_contents).expect("Problems parsing config file"); - tracing::debug!("Config {:?}", app_config); + let app_state: AppState = app_config.into(); - let oidc_router = service_conventions::oidc::router(app_config.auth.clone()); + let oidc_router = service_conventions::oidc::router(app_state.auth.clone()); let app = Router::new() // `GET /` goes to `root` .route("/", get(root)) .route("/user", get(user_handler)) .nest("/oidc", oidc_router) - .with_state(app_config.auth.clone()) + .with_state(app_state.auth.clone()) .layer(CookieManagerLayer::new()) .layer( TraceLayer::new_for_http() @@ -88,6 +105,18 @@ async fn user_handler(user: Option) -> Resp @if let Some(email) = user.email { p{ ( email ) } } + h3 { "scopes" } + ul { + @for scope in &user.scopes { + li { (scope) } + } + } + h3 { "groups" } + ul { + @for group in &user.groups { + li { (group) } + } + } a href="/oidc/login" { "Login" } }