Leptos library for OpenId-Connect (OIDC) authentication handling in Axum applications.
Find a file
2026-02-28 15:28:25 +01:00
.woodpecker ci/init (#7): Add initial woodpecker setup 2026-02-24 20:52:30 +01:00
assets add architecture image 2026-02-22 23:39:06 +01:00
src Create exception rule for auth paths 2026-02-28 15:25:38 +01:00
.gitignore first commit 2026-02-18 00:25:05 +01:00
Cargo.lock Lock file changed 2026-02-28 15:28:25 +01:00
Cargo.toml Crate version bumped to 0.2.3 2026-02-28 15:27:10 +01:00
LICENSE Append docstrings + license 2026-02-22 21:36:35 +01:00
README.md use url crate for typed url in auth config 2026-02-25 02:01:26 +01:00

Leptos Auth Router

A OpenId-Connect (oidc) authentication router with server-function integration for Leptos + Axum apps.

architecture of leptos-auth-router

This crate provides:

  • Login and callback routes
  • Session management via signed cookies
  • Middleware to protect routes

Quick Start

Enable authentication for Leptos routes

use leptos_auth_router::config::{Config, AuthConfig, RouteConfig};
use axum::Router;

// Configure authentication
let auth_config = AuthConfig {
    base_url: url::Url::parse("http://example.com").expect("Invalid base url"),
    issuer_url: url::Url::parse("https://auth.example.com/auth/v1").expect("Invalid issuer url"),
    client_id: "test-client".to_string(),
    client_secret: "your-secret".to_string(),
    cookie_secret: "a-very-long-random-secret".to_string(),
};

// Configure routes
/* Default implementation */
let route_config = RouteConfig {
    prefix: "auth".to_owned(),
    login_path: "login".to_owned(),
    callback_path: "callback".to_owned(),
}; 

// Extend your Axum app with authentication
let app = Router::new()
    .leptos_routes(&leptos_options, routes, {
        let leptos_options = leptos_options.clone();
        move || shell(leptos_options.clone())
    })
    .fallback(leptos_axum::file_and_error_handler(shell))
    .with_state(leptos_options)
    .use_leptos_auth(Config {
        auth: auth_config,
        route: route_config,
    })
    .await;

Access session data in server functions

pub fn App() -> impl IntoView {
    let session_data =
        LocalResource::new(move || async { leptos_auth_router::session::get_auth_session().await });

    view! {
        <p>{move || format!("{:?}", session_data.get())}</p>
    }
}

Leptos compatibility

Crate version Compatible Leptos version
0.1 0.8

Installation

📌 If your are adding this crate to your server application, the ssr feature must be enabled.

cargo add leptos-auth-router

Note: Authentication is handled completely on the server.
Using Leptos starter templates like start-axum may cause server-client separation issues.
For proper server-client separation, use the start-axum-workspace template.

⚠️ Important

This crate is experimental and may contains security issues.

Use at your own risk!
No liability is assumed for any damages or issues resulting from its use.

License

leptos-auth-router is distributed under the MIT License.
For more information, see the LICENSE file.