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

View file

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

View file

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