Utoipa auth endpoint

This commit is contained in:
Antoine Gersant 2025-01-13 22:34:32 -08:00
parent 2e2ddf017b
commit 364710ef79
2 changed files with 11 additions and 3 deletions
src/server

View file

@ -28,7 +28,7 @@ pub fn router() -> OpenApiRouter<App> {
// Basic
.routes(routes!(get_version))
.routes(routes!(get_initial_setup))
.route("/auth", post(post_auth))
.routes(routes!(post_auth))
// Configuration
.route("/settings", get(get_settings))
.route("/settings", put(put_settings))
@ -178,6 +178,14 @@ async fn put_mount_dirs(
Ok(())
}
#[utoipa::path(
post,
path = "/auth",
responses(
(status = 200, body = dto::Authorization),
(status = 401),
),
)]
async fn post_auth(
State(config_manager): State<config::Manager>,
credentials: Json<dto::Credentials>,

View file

@ -15,13 +15,13 @@ pub struct InitialSetup {
pub has_any_users: bool,
}
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, ToSchema)]
pub struct Credentials {
pub username: String,
pub password: String,
}
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, ToSchema)]
pub struct Authorization {
pub username: String,
pub token: String,