Skip to content

Commit

Permalink
feat: display scopes and groups for user
Browse files Browse the repository at this point in the history
  • Loading branch information
philipcristiano committed Mar 19, 2024
1 parent 8c79b02 commit 5d4832b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
1 change: 0 additions & 1 deletion oidc.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"
35 changes: 32 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppConfig> 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;

Expand All @@ -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()
Expand Down Expand Up @@ -88,6 +105,18 @@ async fn user_handler(user: Option<service_conventions::oidc::OIDCUser>) -> 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" }
}
Expand Down

0 comments on commit 5d4832b

Please sign in to comment.