01Axum + Postgres + OAuth

Composable authentication for Rust

Built around Axum and Postgres with custom sessions, email/password flows, OAuth, and a CLI for migrations.

README

rs-auth is an authentication library for Rust. It provides email/password auth, database-backed sessions, email verification, password reset, and OAuth — all designed for Axum and PostgreSQL.

Cargo.toml
[dependencies]
rs-auth = "0.1"
Features
01Email & Password

Built-in credential auth.

Signup, login, logout with secure password hashing, email verification, and password reset.

02Sessions

Database-backed sessions.

Opaque tokens stored in Postgres with signed cookies and configurable expiry.

03Axum Integration

Framework-native.

Router, extractors, middleware, and a prebuilt auth handler you nest into your app.

04OAuth

Social sign-on.

Google and GitHub flows with automatic account linking and state verification.

05PostgreSQL

SQLx-backed storage.

Migrations, session tracking, user management, and OAuth account persistence.

06CLI

Developer tooling.

Run migrations, manage configuration, and scaffold auth setup from the command line.

Quick Start
src/main.rs
use axum::Router;
use rs_auth::axum::{auth_router, AuthState};
use rs_auth::config::AuthConfig;

let config = AuthConfig::builder()
    .database_url(env::var("DATABASE_URL")?)
    .cookie_secret(env::var("COOKIE_SECRET")?)
    .build();

let state = AuthState::new(config).await?;
let auth = auth_router(state.clone());

let app = Router::new()
    .nest("/auth", auth)
    .with_state(state);

let listener = tokio::net::TcpListener::bind("0.0.0.0:3000")
    .await?;
axum::serve(listener, app).await?;
Architecture

rs-auth is a Cargo workspace split into focused crates. Use only what you need, or pull in the facade crate for everything.

rs-auth

Facade crate that re-exports everything.

rs-auth-core

Auth logic, password hashing, token generation.

rs-auth-postgres

SQLx-backed user, session, and OAuth storage.

rs-auth-axum

Axum router, extractors, and middleware.

Get started

Read the docs, install the crate, and ship auth in minutes.

Open Docs