| Crates.io | axum-totp |
| lib.rs | axum-totp |
| version | 0.1.0 |
| created_at | 2026-01-10 01:15:50.208589+00 |
| updated_at | 2026-01-10 01:15:50.208589+00 |
| description | User authentication with TOTP two-factor authentication for Axum web applications |
| homepage | |
| repository | https://github.com/greenpdx/axum-totp |
| max_upload_size | |
| id | 2033271 |
| size | 412,022 |
A Rust web server implementing user authentication with TOTP (Time-based One-Time Password) two-factor authentication, built with Axum and SQLite.
# Clone and build
git clone https://github.com/greenpdx/axum-totp
cd axum-totp
cargo build --release
# Run the server
cargo run --release
The server starts at http://0.0.0.0:8000 and creates a data.db SQLite file for storage.
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /auth/register |
Register a new user | No |
| POST | /auth/login |
Login and get session token | No |
| POST | /auth/profile |
Get user profile | Yes |
| POST | /auth/logout |
Logout and invalidate session | Yes |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /auth/otp/generate |
Generate OTP secret and QR URL | Yes |
| POST | /auth/otp/verify |
Verify and enable 2FA | Yes |
| POST | /auth/otp/validate |
Validate OTP token | Yes |
| POST | /auth/otp/disable |
Disable 2FA | Yes |
For authenticated endpoints, pass the session token in the X-Session-Token header:
curl -X POST http://localhost:8000/auth/profile \
-H "Content-Type: application/json" \
-H "X-Session-Token: your_session_token"
curl -X POST http://localhost:8000/auth/register \
-H "Content-Type: application/json" \
-d '{"name": "John Doe", "email": "john@example.com", "password": "securepassword"}'
curl -X POST http://localhost:8000/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "john@example.com", "password": "securepassword"}'
Response:
{
"status": "success",
"session_token": "abc123...",
"otp_enabled": false
}
curl -X POST http://localhost:8000/auth/profile \
-H "Content-Type: application/json" \
-H "X-Session-Token: your_session_token"
curl -X POST http://localhost:8000/auth/otp/generate \
-H "Content-Type: application/json" \
-H "X-Session-Token: your_session_token"
Response:
{
"base32": "JBSWY3DPEHPK3PXP...",
"otpauth_url": "otpauth://totp/CrMep:john@example.com?secret=..."
}
curl -X POST http://localhost:8000/auth/otp/verify \
-H "Content-Type: application/json" \
-H "X-Session-Token: your_session_token" \
-d '{"otp_token": "123456"}'
curl -X POST http://localhost:8000/auth/otp/validate \
-H "Content-Type: application/json" \
-H "X-Session-Token: your_session_token" \
-d '{"otp_token": "123456"}'
curl -X POST http://localhost:8000/auth/otp/disable \
-H "Content-Type: application/json" \
-H "X-Session-Token: your_session_token"
curl -X POST http://localhost:8000/auth/logout \
-H "Content-Type: application/json" \
-H "X-Session-Token: your_session_token"
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
src/
├── main.rs # Server setup and router configuration
├── lib.rs # Library exports
├── acl.rs # Authentication middleware
├── models.rs # Data models, validation, session management
├── services.rs # API route handlers
└── response.rs # Response types
migrations/
└── 001_initial.sql # Database schema
tests/
└── integration_tests.rs # API integration tests
LGPL-2.1