Ruts: Rust Tower Session for HTTP Applications
Ruts is a robust, flexible session management library for Rust web applications. It provides a seamless way to handle user sessions in tower-based web frameworks, with a focus on security, performance, and ease of use.
Installation
Add the following to your Cargo.toml:
[]
= "0.2.0"
Quick Start
Here's a basic example of how to use ruts with axum:
use ;
use ;
use RedisStore;
use RedisClient;
use Arc;
use ClientLike;
use CookieManagerLayer;
async
async
Usage
Setting Up the SessionLayer with cookie support
let store = new;
let session_layer = new
.with_cookie_options;
Setting Up the SessionLayer without cookie support
let store = new;
let session_layer = new;
Using Sessions in axum request handlers
ruts provides an extractor for axum that allows you to easily access the session in your request handlers:
async
Configuration
You can customize various aspects of session management using CookieOptions:
let cookie_options = build
.name
.http_only
.same_site
.secure
.max_age // 2 hours
.path;
Security Considerations
- Always use HTTPS in production to protect session cookies.
- Set appropriate
SameSiteandSecureflags for cookies. - Regularly regenerate session IDs to prevent session fixation attacks.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.