Add logout url

This commit is contained in:
Simon Goller 2024-06-18 08:01:52 +02:00
parent eb54665596
commit 7d59cbde11
4 changed files with 17 additions and 1 deletions

View file

@ -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"] }

View file

@ -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<Redirect, StatusCode> {
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<str>,
@ -302,6 +315,7 @@ pub async fn start_server<RestState: RestStateDef>(rest_state: RestState) {
.layer(OidcLoginLayer::<EmptyAdditionalClaims>::new());
app.route("/authenticate", get(login))
.route("/logout", get(logout))
.layer(oidc_login_service)
};