1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! # 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
//!
//! ```rust,no_run
//! 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() {
//! // Set up Torii with your storage backend
//! let repositories = Arc::new(SeaORMRepositoryProvider::new(pool));
//! let torii = Arc::new(Torii::new(repositories));
//!
//! // Create auth routes with custom cookie configuration
//! let auth_routes = routes(torii.clone())
//! .with_cookie_config(CookieConfig::development());
//!
//! // Create your application router
//! let app = Router::new()
//! .nest("/auth", auth_routes)
//! .route("/protected", get(protected_handler))
//! .layer(require_auth(torii));
//!
//! // Run your server
//! 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!"
//! }
//! ```
pub use ;
pub use ;
pub use ;
pub use create_router;
pub use ;
use Router;
use Arc;
use Torii;
use RepositoryProvider;
/// Create authentication routes for your Axum application.
///
/// This function creates a router with all available authentication endpoints
/// based on the features enabled in your Cargo.toml.
///
/// # Arguments
///
/// * `torii` - An Arc-wrapped Torii instance configured with your storage backend
///
/// # Returns
///
/// A Router that can be nested into your application at any path (e.g., "/auth")
///
/// # Example
///
/// ```rust,no_run
/// let auth_routes = torii_axum::routes(torii);
/// let app = Router::new().nest("/auth", auth_routes);
/// ```
/// Builder for configuring authentication routes