Skip to main content

potree_auth/authentication/http/
router.rs

1use std::sync::LazyLock;
2
3use axum::Extension;
4use axum::Router;
5use axum::routing::get;
6use web_route::WebRoute;
7
8use super::super::application::service::AuthenticationService;
9use super::route_handlers;
10use super::state::State;
11
12pub static LOGIN: LazyLock<WebRoute> = LazyLock::new(|| WebRoute::new("/login"));
13pub static CALLBACK: LazyLock<WebRoute> = LazyLock::new(|| WebRoute::new("/callback"));
14
15/// Builds a router that performs OIDC authentication.
16///
17/// **Note:** There should be an active [`tower_sessions`] middleware available
18/// in the router's middleware stack.
19pub fn build_router(authentication_service: AuthenticationService) -> Router {
20    let state = State {
21        authentication_service,
22    };
23
24    Router::new()
25        .route(&LOGIN, get(route_handlers::login))
26        .route(&CALLBACK, get(route_handlers::callback))
27        .layer(Extension(state))
28}