Torii Axum Integration
This crate provides Axum routes and middleware for the Torii authentication framework.
It offers a simple way to add authentication to your Axum application with support for
multiple authentication methods.
Features
- Core Authentication: Session management, user info, health checks
- Password Authentication (feature = "password"): Registration, login, password changes
- Magic Link Authentication (feature = "magic-link"): Passwordless email authentication
- OAuth (feature = "oauth"): Coming soon
- Passkey (feature = "passkey"): Coming soon
Example Usage
use std::sync::Arc;
use axum::{Router, routing::get};
use torii::{Torii, SeaORMRepositoryProvider};
use torii_axum::{routes, require_auth, CookieConfig};
#[tokio::main]
async fn main() {
let repositories = Arc::new(SeaORMRepositoryProvider::new(pool));
let torii = Arc::new(Torii::new(repositories));
let auth_routes = routes(torii.clone())
.with_cookie_config(CookieConfig::development());
let app = Router::new()
.nest("/auth", auth_routes)
.route("/protected", get(protected_handler))
.layer(require_auth(torii));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
async fn protected_handler() -> &'static str {
"This route requires authentication!"
}