rs-auth
rs-auth.com · crates.io · docs.rs · GitHub
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) is available for stable Google and GitHub login and callback flows.
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
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, OAuth accounts, and OAuth state.
Generate Migration
Generates a new migration file template.
Cleanup Expired Tokens
Removes expired sessions, verification tokens, and OAuth state from the database.
OAuth
Google and GitHub OAuth providers are supported. Stable endpoints are:
GET /auth/login/{provider}GET /auth/callback/{provider}
Stable behavior includes:
- OAuth login
- account creation
- implicit account linking
- session creation
- JSON callback responses
- redirect-mode callback responses
Configure OAuth with OAuthConfig:
use ;
let mut config = default;
config.oauth = OAuthConfig ;
OAuth transient state is stored separately from verification tokens. Each record stores:
provider_idcsrf_statepkce_verifierexpires_at
This keeps email/reset verification tokens isolated from OAuth login state and allows operational cleanup to handle both flows independently.
Out of scope for the current OAuth milestone:
- additional providers
- token refresh workflows
- unlinking accounts
- admin tooling
- provider management UX
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 |
| GET | /auth/callback/{provider} |
OAuth callback handler |
License
Licensed under either of:
- MIT License
- Apache License, Version 2.0
at your option.