2023-08-18 10:59:50 +02:00
|
|
|
use axum::{
|
|
|
|
|
routing::{get, post},
|
|
|
|
|
Router,
|
|
|
|
|
};
|
2023-08-22 19:29:40 +02:00
|
|
|
use tower_cookies::CookieManagerLayer;
|
2023-08-18 10:59:50 +02:00
|
|
|
|
|
|
|
|
use crate::state::RoutableAppState;
|
|
|
|
|
|
2023-08-26 12:39:11 +00:00
|
|
|
mod authorize;
|
2023-08-18 10:59:50 +02:00
|
|
|
mod index;
|
|
|
|
|
mod login;
|
2023-08-25 10:16:59 +00:00
|
|
|
mod logout;
|
2023-08-18 10:59:50 +02:00
|
|
|
|
|
|
|
|
/// Build a router for the application, in a specific subpath eg `/yunohost/sso/`
|
|
|
|
|
pub fn router(subpath: Option<String>, state: RoutableAppState) -> Router {
|
|
|
|
|
let app = Router::new()
|
|
|
|
|
.route("/", get(index::route))
|
2023-08-22 17:00:55 +02:00
|
|
|
.route("/login/", post(login::route))
|
2023-08-25 10:16:59 +00:00
|
|
|
.route("/logout/", get(logout::route))
|
2023-08-26 12:39:11 +00:00
|
|
|
.route("/authorize/", get(authorize::route))
|
2023-08-22 19:29:40 +02:00
|
|
|
.layer(CookieManagerLayer::new())
|
2023-08-18 10:59:50 +02:00
|
|
|
.with_state(state);
|
|
|
|
|
if let Some(p) = subpath {
|
|
|
|
|
Router::new()
|
|
|
|
|
.nest(&p, app)
|
|
|
|
|
} else {
|
|
|
|
|
app
|
|
|
|
|
}
|
2023-08-23 12:33:06 +00:00
|
|
|
}
|