Expand description
PostgreSQL storage backend for Torii
This crate provides a PostgreSQL-based storage implementation for the Torii authentication framework. It includes implementations for all core storage traits and provides a complete authentication storage solution using PostgreSQL as the underlying database.
§Features
- User Management: Store and retrieve user accounts with email verification support
- Session Management: Handle user sessions with configurable expiration
- Password Authentication: Secure password hashing and verification
- OAuth Integration: Store OAuth account connections and tokens
- Passkey Support: WebAuthn/FIDO2 passkey storage and challenge management
- Database Migrations: Automatic schema management and upgrades
- Production Ready: Designed for high-performance production workloads
§Usage
use torii_storage_postgres::PostgresStorage;
use torii_core::UserId;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to PostgreSQL database
let storage = PostgresStorage::connect("postgresql://user:password@localhost/torii").await?;
// Run migrations to set up the schema
storage.migrate().await?;
// Use with Torii (PostgresRepositoryProvider not yet implemented)
// let repositories = std::sync::Arc::new(storage.into_repository_provider());
// let torii = torii::Torii::new(repositories);
Ok(())
}
§Current Status
This crate currently provides the base PostgreSQL storage implementation with user and session management. The full repository provider implementation is still in development.
§Storage Implementations
This crate implements the following storage traits:
UserStorage
- User account managementSessionStorage
- Session management- Password repository for secure password storage
- OAuth repository for third-party authentication
- Passkey repository for WebAuthn support
§Database Schema
The PostgreSQL schema includes tables for:
users
- User accounts and profile informationsessions
- Active user sessionspasswords
- Hashed password credentialsoauth_accounts
- Connected OAuth accountspasskeys
- WebAuthn passkey credentialspasskey_challenges
- Temporary passkey challenges
All tables include appropriate indexes and constraints for optimal query performance and data integrity.