use poem_openapi::{
ApiResponse, Object,
payload::{Json, PlainText},
};
#[derive(ApiResponse)]
pub enum CreateUser {
#[oai(status = 200)]
Bearer(PlainText<String>),
#[oai(status = 400)]
NameIsTooComplex,
#[oai(status = 409)]
NameAlreadyTaken,
#[oai(status = 500)]
Other,
}
#[derive(Default, Object)]
pub struct LoginChallenges {
pub password: bool,
pub totp: bool,
pub webauthn: Option<serde_json::Value>,
}
#[derive(ApiResponse)]
pub enum PrepareLogin {
#[oai(status = 200)]
Challenges(Json<LoginChallenges>),
#[oai(status = 400)]
NameIsTooComplex,
#[oai(status = 404)]
UsernameNotFound,
#[oai(status = 500)]
Other,
}
#[derive(ApiResponse)]
pub enum FinishLogin {
#[oai(status = 200)]
Bearer(PlainText<String>),
#[oai(status = 400)]
InvalidDataFormat,
#[oai(status = 401)]
WrongUsername,
#[oai(status = 403)]
Unauthorized,
#[oai(status = 500)]
Other,
}
#[derive(Object)]
pub struct CurrentCredentialsList {
pub password: bool,
pub totp: bool,
pub webauthn_keys: usize,
}
#[derive(ApiResponse)]
pub enum CurrentCredentials {
#[oai(status = 200)]
List(Json<CurrentCredentialsList>),
#[oai(status = 500)]
Other,
}
#[derive(ApiResponse)]
pub enum CurrentWebauthnCredentials {
#[oai(status = 200)]
List(Json<Vec<WebAuthnCredential>>),
#[oai(status = 500)]
Other,
}
#[derive(Object)]
pub struct WebAuthnCredential {
pub name: String,
}
#[derive(ApiResponse)]
pub enum SimpleTask {
#[oai(status = 204)]
Done,
#[oai(status = 400)]
BadInput,
#[oai(status = 403)]
InsufficientPermissions,
#[oai(status = 500)]
Failed,
}
#[derive(Object)]
pub struct NewTotpSetup {
pub seed_base32: String,
pub authenticator_url: String,
}
#[derive(ApiResponse)]
pub enum NewTotp {
#[oai(status = 200)]
Setup(Json<NewTotpSetup>),
#[oai(status = 403)]
InsufficientPermissions,
#[oai(status = 500)]
Other,
}
#[derive(ApiResponse)]
pub enum NewWebauthnCredential {
#[oai(status = 200)]
Setup(Json<serde_json::Value>),
#[oai(status = 403)]
InsufficientPermissions,
#[oai(status = 500)]
Other,
}
#[derive(ApiResponse)]
pub enum ConfirmNewWebauthnCredential {
#[oai(status = 204)]
Done,
#[oai(status = 400)]
KeyNameIsTooComplex,
#[oai(status = 401)]
AuthFailed,
#[oai(status = 403)]
InsufficientPermissions,
#[oai(status = 422)]
BadWebauthnPayload,
#[oai(status = 500)]
Other,
}