Files
madbase/auth/src/models.rs
Vlad Durnea 38cab8c246
Some checks failed
CI/CD Pipeline / lint (push) Successful in 3m45s
CI/CD Pipeline / integration-tests (push) Failing after 58s
CI/CD Pipeline / unit-tests (push) Failing after 1m2s
CI/CD Pipeline / e2e-tests (push) Has been skipped
CI/CD Pipeline / build (push) Has been skipped
Verify M2/M3 implementation, fix regressions against M0/M1
Regressions fixed:
- gateway/src/worker.rs: missing session_manager field in AuthState (M3 regression)
- gateway/src/main.rs: same missing field in monolithic gateway
- storage/src/handlers.rs: removed unused validate_role (now handled by RlsTransaction)

M2 Storage Pillar — verified complete:
- StorageBackend trait with full API (put/get/delete/copy/head/list/multipart)
- AwsS3Backend implementation with streaming get_object
- StorageMode enum (Cloud/SelfHosted) in Config
- All routes: CRUD buckets, CRUD objects, copy, move, sign, public URL, health
- Bucket constraints: file_size_limit + allowed_mime_types enforced on upload
- TUS resumable uploads with S3 multipart (5MB chunking)
- Image transforms run via spawn_blocking
- docker-compose.pillar-storage.yml, templates/storage-node.yaml
- Shared Docker network on all pillar compose files

M3 Auth Completeness — verified complete:
- POST /logout revokes refresh tokens + Redis sessions
- GET /settings returns provider availability
- POST /magiclink with hashed token storage
- DELETE /user soft-delete with token revocation
- Recovery flow accepts new password
- Email change requires re-verification via token
- OAuth callback redirects with fragment tokens
- MFA verify returns aal2 JWT with amr claims
- MFA challenge validates factor ownership
- SessionManager wired into login/logout
- GET /sessions returns active sessions
- Configurable ACCESS_TOKEN_LIFETIME
- Claims model extended with session_id, aal, amr

Tests: 62 passed, 0 failed, 11 ignored (external services)
Warnings: 0
Made-with: Cursor
2026-03-15 14:40:48 +02:00

105 lines
2.8 KiB
Rust

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use uuid::Uuid;
use validator::Validate;
#[derive(Debug, Serialize, Deserialize, FromRow, Clone)]
pub struct User {
pub id: Uuid,
pub email: String,
#[serde(skip)]
pub encrypted_password: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub last_sign_in_at: Option<DateTime<Utc>>,
#[serde(rename = "app_metadata")]
pub raw_app_meta_data: serde_json::Value,
#[serde(rename = "user_metadata")]
pub raw_user_meta_data: serde_json::Value,
pub is_super_admin: Option<bool>,
pub confirmed_at: Option<DateTime<Utc>>,
pub email_confirmed_at: Option<DateTime<Utc>>,
pub phone: Option<String>,
pub phone_confirmed_at: Option<DateTime<Utc>>,
pub confirmation_token: Option<String>,
pub recovery_token: Option<String>,
pub email_change_token_new: Option<String>,
pub email_change: Option<String>,
pub deleted_at: Option<DateTime<Utc>>,
}
#[derive(Debug, Deserialize, Validate)]
pub struct SignUpRequest {
#[validate(email)]
pub email: String,
#[validate(length(min = 6, message = "Password must be at least 6 characters"))]
pub password: String,
pub data: Option<serde_json::Value>,
}
#[derive(Debug, Deserialize, Validate)]
pub struct SignInRequest {
#[validate(email)]
pub email: String,
pub password: String,
}
#[derive(Debug, Serialize)]
pub struct AuthResponse {
pub access_token: String,
pub token_type: String,
pub expires_in: i64,
pub refresh_token: String,
pub user: User,
}
#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct RefreshToken {
pub id: i64,
pub token: String,
pub user_id: Uuid,
pub revoked: bool,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub parent: Option<String>,
pub session_id: Option<Uuid>,
}
#[derive(Debug, Deserialize, Validate)]
pub struct RecoverRequest {
#[validate(email)]
pub email: String,
}
#[derive(Debug, Deserialize)]
pub struct VerifyRequest {
pub r#type: String,
pub token: String,
pub password: Option<String>,
}
#[derive(Debug, Deserialize, Validate)]
pub struct UserUpdateRequest {
#[validate(email)]
pub email: Option<String>,
#[validate(length(min = 6, message = "Password must be at least 6 characters"))]
pub password: Option<String>,
pub data: Option<serde_json::Value>,
}
#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct MfaChallenge {
pub id: Uuid,
pub factor_id: Uuid,
pub created_at: DateTime<Utc>,
pub verified_at: Option<DateTime<Utc>>,
pub ip_address: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AmrEntry {
pub method: String,
pub timestamp: usize,
}