seamless_auth/lib.rs
1//! A [Seamless Auth](https://github.com/fells-code/seamless-auth-api) server adapter for Axum.
2//!
3//! The adapter sits in front of the Seamless Auth API. Browsers talk to it over
4//! `HttpOnly` cookies on the application's own domain, native clients over bearer
5//! tokens, and it talks to the auth API over bearer tokens and a service token.
6//! Which routes it serves, and what each does to the session, comes from the auth
7//! API's adapter manifest.
8//!
9//! ```no_run
10//! use axum::{Json, Router, routing::get};
11//! use seamless_auth::{Adapter, User};
12//!
13//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
14//! let auth = Adapter::builder(std::env::var("AUTH_SERVER_URL")?)
15//! .cookie_secret(std::env::var("COOKIE_SECRET")?)
16//! .service_secret(std::env::var("SEAMLESS_SERVICE_TOKEN")?)
17//! .jwks_kid(std::env::var("JWKS_KID")?)
18//! .build()?;
19//!
20//! let app: Router = Router::new()
21//! .route(
22//! "/api/me",
23//! get(|user: User| async move { Json(serde_json::json!({ "id": user.id })) })
24//! .route_layer(auth.require_auth()),
25//! )
26//! .nest("/auth", auth.router());
27//!
28//! let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
29//! axum::serve(
30//! listener,
31//! app.into_make_service_with_connect_info::<std::net::SocketAddr>(),
32//! )
33//! .await?;
34//! # Ok(())
35//! # }
36//! ```
37
38mod adapter;
39mod client_ip;
40mod console;
41mod cookies;
42mod delivery;
43mod guard;
44mod jwks;
45mod jwt;
46mod manifest;
47mod options;
48mod origin;
49mod refresh;
50mod routes;
51mod service_token;
52
53#[cfg(test)]
54mod tests;
55
56pub use adapter::Adapter;
57pub use client_ip::{InvalidProxy, TrustedProxies};
58pub use delivery::{Delivery, DeliveryError};
59pub use guard::{RequireAuth, RequireAuthLayer, Unauthenticated, User};
60pub use manifest::{MANIFEST_PATH, Manifest, ManifestError, ManifestRoute, PickBody};
61pub use options::{BuildError, Builder, SameSite};