rs-auth
Composable authentication for Rust, inspired by Better Auth. The rs-auth facade crate re-exports rs-auth-core, rs-auth-postgres, and rs-auth-axum for convenient access to the authentication stack.
Current Status
Phase 1 (Email/Password Authentication) is complete and production-ready.
Phase 2 (OAuth) exists with support for Google and GitHub providers, but is still early and experimental. The API may change in future releases.
Features
- Email/password signup and login
- Argon2id password hashing
- Database-backed sessions with opaque tokens (SHA-256 hashed)
- Email verification
- Password reset
- Signed cookies (via axum-extra)
- Configurable session and token TTLs
- Auto sign-in after signup
- CLI for migrations and cleanup
- OAuth login and callback for Google and GitHub (experimental)
Workspace Layout
rs-auth/
├── auth/ -> rs-auth (facade crate)
├── core/ -> rs-auth-core (domain logic)
├── pg/ -> rs-auth-postgres (PostgreSQL store)
├── axum/ -> rs-auth-axum (Axum handlers & router)
├── cli/ -> rs-auth-cli (CLI tool)
└── examples/
└── basic/ -> minimal example app
Quick Start
Add rs-auth to your Cargo.toml:
[]
= "0.1"
= { = "0.8", = ["runtime-tokio", "postgres"] }
= "0.8"
= { = "0.10", = ["cookie-signed"] }
= { = "1", = ["full"] }
= "0.3"
Create a minimal application:
use SignedCookieJar;
use ;
use ;
use ;
use ;
use json;
async
async
Configuration
The AuthConfig struct controls authentication behavior:
EmailConfig
CookieConfig
CLI
The rs-auth-cli binary provides three commands:
Run Migrations
Creates the necessary database tables for users, sessions, verification tokens, and OAuth accounts.
Generate Migration
Generates a new migration file template.
Cleanup Expired Tokens
Removes expired sessions and verification tokens from the database.
OAuth (Experimental)
Google and GitHub OAuth providers are supported. Configure OAuth with OAuthConfig:
use ;
let mut config = default;
config.oauth = OAuthConfig ;
OAuth transient state (CSRF tokens and PKCE verifiers) is currently stored in the verifications table to reuse existing infrastructure. This approach may change in future versions if OAuth features expand significantly.
Note: The OAuth implementation is early and the API may change in future releases.
API Endpoints
The auth_router provides the following endpoints:
| Method | Path | Description |
|---|---|---|
| POST | /auth/signup |
Create a new user account |
| POST | /auth/login |
Log in with email and password |
| POST | /auth/logout |
Log out and invalidate session |
| GET | /auth/session |
Get current session information |
| GET | /auth/sessions |
List all sessions for current user |
| GET | /auth/verify/{token} |
Verify email with token |
| POST | /auth/forgot |
Request password reset |
| POST | /auth/reset |
Reset password with token |
| GET | /auth/login/{provider} |
Initiate OAuth login (experimental) |
| GET | /auth/callback/{provider} |
OAuth callback handler (experimental) |
License
Licensed under either of:
- MIT License
- Apache License, Version 2.0
at your option.