This project is a complete authentication service built with Rust, featuring a two-factor authentication system. It is designed as a microservice and includes both an auth-service and a corresponding app-service to demonstrate its functionality.
The repository is organized into the following main components:
auth-service: The core authentication microservice. It handles user registration, login, and two-factor authentication.app-service: A web application that uses theauth-serviceto manage user sessions and protect routes.compose.yml: Docker Compose file to orchestrate the services and their dependencies (PostgreSQL and Redis)..github: Contains GitHub Actions workflows for CI/CD.
- User Management:
- User registration with password hashing (Argon2).
- Secure login and logout.
- Two-Factor Authentication (2FA):
- Generates and sends 2FA codes via email.
- Verifies 2FA codes for enhanced security.
- Token-Based Authentication:
- Uses JSON Web Tokens (JWT) for session management.
- Includes a token blacklist to handle logouts and prevent token reuse.
- Configuration:
- Highly configurable via environment variables and command-line arguments.
- Supports different backends for storage and caching (in-memory, PostgreSQL, Redis).
- Email Integration:
- Sends emails using Postmark (or a mock service for testing).
- API Schema:
- The API is documented using OpenAPI (see
api_schema.yml).
- The API is documented using OpenAPI (see
- Web Interface:
- Provides a simple UI for registration, login, and accessing protected content.
- Built with Axum and Askama for templating.
- Protected Routes:
- Demonstrates how to protect routes and manage user sessions with the
auth-service.
- Demonstrates how to protect routes and manage user sessions with the
- Web Framework:
axum - Database:
sqlx(with PostgreSQL) - Caching:
redis - Authentication:
argon2,jsonwebtoken - Configuration:
clap,dotenvy - Email:
reqwest(for Postmark API) - Other:
tokio,serde,tracing
- Web Framework:
axum - Templating:
askama - HTTP Client:
reqwest - Other:
tokio,serde,tracing
- Docker and Docker Compose
- Rust toolchain
-
Clone the repository:
git clone https://github.com/FeAmCor/letsgetrusty-auth-service.git cd letsgetrusty-auth-service -
Set up environment variables:
- Create a
.envfile based on the provided examples incompose.yml. - You will need to provide credentials for the database and any external services (like Postmark).
- Create a
-
Build and run with Docker Compose:
docker-compose up --build
-
Access the services:
app-servicewill be available athttp://localhost:8000.auth-servicewill be available athttp://localhost:3000.
The project includes a CI/CD pipeline using GitHub Actions, which automates testing, building, and deploying the services.