From 7d59cbde11628b9dde60627a09f6830052de83f8 Mon Sep 17 00:00:00 2001 From: Simon Goller Date: Tue, 18 Jun 2024 08:01:52 +0200 Subject: [PATCH] Add logout url --- Cargo.lock | 1 + dao_impl/src/sales_person.rs | 2 +- rest/Cargo.toml | 1 + rest/src/lib.rs | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 01ed12b..5b06d15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1739,6 +1739,7 @@ dependencies = [ "axum", "axum-oidc", "bytes", + "http 1.1.0", "http-body 1.0.0", "rest-types", "serde", diff --git a/dao_impl/src/sales_person.rs b/dao_impl/src/sales_person.rs index a773a0d..40c5be1 100644 --- a/dao_impl/src/sales_person.rs +++ b/dao_impl/src/sales_person.rs @@ -106,7 +106,7 @@ impl SalesPersonDao for SalesPersonDaoImpl { let id = entity.id.as_bytes().to_vec(); let version = entity.version.as_bytes().to_vec(); let name = entity.name.as_ref(); - let background_color = entity.name.as_ref(); + let background_color = entity.background_color.as_ref(); let inactive = entity.inactive; let deleted = entity.deleted.as_ref().map(|deleted| deleted.to_string()); query!("UPDATE sales_person SET name = ?, background_color = ?, inactive = ?, deleted = ?, update_version = ?, update_process = ? WHERE id = ?", name, background_color, inactive, deleted, version, process, id) diff --git a/rest/Cargo.toml b/rest/Cargo.toml index 07a86f0..618537f 100644 --- a/rest/Cargo.toml +++ b/rest/Cargo.toml @@ -15,6 +15,7 @@ mock_auth = [] [dependencies] axum = "0.7.5" bytes = "1.6.0" +http = "1.1.0" http-body = "1.0.0" serde_json = "1.0.116" time = { version = "0.3.36", features = ["serde-human-readable"] } diff --git a/rest/src/lib.rs b/rest/src/lib.rs index 5bf5e31..f640d22 100644 --- a/rest/src/lib.rs +++ b/rest/src/lib.rs @@ -252,6 +252,19 @@ pub async fn login() -> Redirect { Redirect::to("/") } +#[cfg(feature = "oidc")] +use axum_oidc::OidcRpInitiatedLogout; +#[cfg(feature = "oidc")] +use http::StatusCode; +#[cfg(feature = "oidc")] +pub async fn logout(logout_extractor: OidcRpInitiatedLogout) -> Result { + if let Ok(logout_uri) = logout_extractor.uri() { + Ok(Redirect::to(logout_uri.path())) + } else { + Err(StatusCode::BAD_REQUEST) + } +} + #[derive(Serialize, Deserialize, Clone, Debug)] pub struct AuthInfoTO { pub user: Arc, @@ -302,6 +315,7 @@ pub async fn start_server(rest_state: RestState) { .layer(OidcLoginLayer::::new()); app.route("/authenticate", get(login)) + .route("/logout", get(logout)) .layer(oidc_login_service) };