diff options
Diffstat (limited to 'src/api/mod.rs')
| -rw-r--r-- | src/api/mod.rs | 93 |
1 files changed, 50 insertions, 43 deletions
diff --git a/src/api/mod.rs b/src/api/mod.rs index d91c434..c4265fb 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -44,7 +44,8 @@ use crate::state::AppState; /// Builds the complete HTTP router. Everything except the API description (`/swagger-ui`, /// `/openapi.yaml`), `/health`, `/ready` and logging in by key (`/auth/challenge`, -/// `/auth/login/key`, which prove the user themselves) is authenticated. +/// `/auth/login/key`, `/auth/login/party`, which prove the user themselves) is +/// authenticated. pub(crate) fn router(state: AppState, auth_state: AuthState, debug_api: bool) -> Router { let mut api: Router<AppState> = Router::new() .route("/store", get(store::get_store_root)) @@ -118,48 +119,54 @@ pub(crate) fn router(state: AppState, auth_state: AuthState, debug_api: bool) -> } // Inside authentication, which finds the user: what the user may do. - api.layer(middleware::from_fn_with_state( - state.clone(), - access::authorize, - )) - .layer(middleware::from_fn_with_state( - auth_state.clone(), - basic_auth, - )) - // Who has a password here (`/auth/keys`: a user's last key goes only then). - .layer(axum::Extension(auth_state)) - // A stream answered to a token ends with it (expired, revoked, its session ended). - .layer(middleware::from_fn_with_state( - state.clone(), - login::streams_end, - )) - // Outside authentication: a token, if the request brings one, names the user. - .layer(middleware::from_fn_with_state(state.clone(), login::bearer)) - // Outermost: pages of other origins, and their preflights, which bring no - // credentials. - .layer(middleware::from_fn_with_state(state.clone(), cors::cors)) - // The hand-written spec (`docs/openapi.yaml`), and the Swagger UI showing it. - .merge( - // Relative to the UI's page (`/swagger-ui/`), so it is found behind a proxy that - // serves the API under a path of its own too. - SwaggerUi::new("/swagger-ui").config(utoipa_swagger_ui::Config::from("../openapi.yaml")), - ) - .route("/openapi.yaml", get(openapi_spec)) - // Logging in by key: a challenge, and the token for it signed, without a password. - .route("/auth/challenge", axum::routing::post(login::challenge)) - .route("/auth/login/key", axum::routing::post(login::login_key)) - .route("/health", get(health::node_health)) - // To log in to the dashboard on, and the dashboard's page, without authentication - // (they hold nothing). - .route("/login", get(dashboard_login)) - .route("/admin/dashboard", get(dashboard_page)) - .route("/ready", get(health::ready)) - // Outermost, so authentication failures get the error body too. - .layer(middleware::from_fn(json_errors)) - .layer(middleware::from_fn(relative_redirects)) - // A line per request, as it is answered. - .layer(middleware::from_fn(request_log::log_requests)) - .with_state(state) + let router = api + .layer(middleware::from_fn_with_state( + state.clone(), + access::authorize, + )) + .layer(middleware::from_fn_with_state( + auth_state.clone(), + basic_auth, + )) + // Who has a password here (`/auth/keys`: a user's last key goes only then). + .layer(axum::Extension(auth_state)) + // A stream answered to a token ends with it (expired, revoked, its session ended). + .layer(middleware::from_fn_with_state( + state.clone(), + login::streams_end, + )) + // Outside authentication: a token, if the request brings one, names the user. + .layer(middleware::from_fn_with_state(state.clone(), login::bearer)) + // Outermost: pages of other origins, and their preflights, which bring no + // credentials. + .layer(middleware::from_fn_with_state(state.clone(), cors::cors)) + // The hand-written spec (`docs/openapi.yaml`), and the Swagger UI showing it. + .merge( + // Relative to the UI's page (`/swagger-ui/`), so it is found behind a proxy that + // serves the API under a path of its own too. + SwaggerUi::new("/swagger-ui") + .config(utoipa_swagger_ui::Config::from("../openapi.yaml")), + ) + .route("/openapi.yaml", get(openapi_spec)) + // Logging in by key: a challenge, and the token for it signed, without a password. + .route("/auth/challenge", axum::routing::post(login::challenge)) + .route("/auth/login/key", axum::routing::post(login::login_key)); + // A party's login by its key, on a node holding a federated store. + #[cfg(feature = "federation")] + let router = router.route("/auth/login/party", axum::routing::post(login::login_party)); + router + .route("/health", get(health::node_health)) + // To log in to the dashboard on, and the dashboard's page, without authentication + // (they hold nothing). + .route("/login", get(dashboard_login)) + .route("/admin/dashboard", get(dashboard_page)) + .route("/ready", get(health::ready)) + // Outermost, so authentication failures get the error body too. + .layer(middleware::from_fn(json_errors)) + .layer(middleware::from_fn(relative_redirects)) + // A line per request, as it is answered. + .layer(middleware::from_fn(request_log::log_requests)) + .with_state(state) } /// The HTTP router of a node that only relays (`--relay-only`): its figures and the log |
