mellon 0.1.0

Library for adding contemporary authentication to rust-based websites.
Documentation
use poem_openapi::{
    ApiRequest, Object,
    payload::{Json, PlainText},
};

#[derive(ApiRequest)]
pub enum CreateUser {
    WithName(PlainText<String>),
}

#[derive(ApiRequest)]
pub enum PrepareLogin {
    WithName(PlainText<String>),
}

#[derive(Object)]
pub struct AuthenticationChallengeResponse {
    /// The user you want to log in as
    pub username: String,
    /// The password for that user (if any)
    pub password: Option<String>,
    /// The current TOTP value (if any)
    pub totp: Option<u32>,
    /// The webauthn response (if needed)
    pub pubkey_credential: Option<serde_json::Value>,
    /// If you want to change your credentials you need an existing login
    pub existing_jwt: Option<String>,
}

#[derive(ApiRequest)]
pub enum FinishLogin {
    WithName(Json<AuthenticationChallengeResponse>),
}

#[derive(ApiRequest)]
pub enum SetPassword {
    NewPassword(PlainText<String>),
}

#[derive(Object)]
pub struct TotpLabel {
    pub label: String,
    pub issuer: String,
}

#[derive(ApiRequest)]
pub enum NewTotp {
    WithLabel(Json<TotpLabel>),
}

#[derive(ApiRequest)]
pub enum ConfirmNewTotp {
    CurrentTotp(PlainText<String>),
}

#[derive(Object)]
pub struct WebauthnRegisterChallengeResponse {
    pub key_name: String,
    /// Type-erased `webauthn_rs::prelude::RegisterPublicKeyCredential`
    pub register_credential: serde_json::Value,
}

#[derive(ApiRequest)]
pub enum ConfirmNewWebauthnCredential {
    ChallengeResponse(Json<WebauthnRegisterChallengeResponse>),
}

#[derive(ApiRequest)]
pub enum DeleteWebAuthnCredential {
    WithKeyName(PlainText<String>),
}