MyGit

AscendingCreations/AxumSession

Fork: 36 Star: 155 (更新于 2024-12-02 07:44:09)

license: MIT

Language: Rust .

Axum Session Management Libraries that use Sqlx

最后发布版本: v0.14.0 ( 2024-04-13 03:01:13)

GitHub网址

Axum Session

https://crates.io/crates/axum_session Docs Discord Server

📑 Overview

`axum_session` provide's a Session management middleware that stores all session data within a MemoryStore internally. Optionally it can save data to a persistent database for long term storage. Uses Cookie or Header stored UUID's to sync back to the session store.

  • Cookies or Header Store of Generated Session UUID and a Store Boolean.
  • Uses a DatabasePool Trait so you can implement your own Sub Storage Layer.
  • Convenient API for Session no need to mark as Read or Write making Usage Easier.
  • Uses dashmap for internal memory lookup and storage to achieve high throughput.
  • Uses Serdes for Data Serialization so it can store any Serdes supported type's into the Sessions data.
  • Supports Redis, SurrealDB, MongoDB and SQLx optional Databases out of the Box.
  • Supports Memory Only usage. No need to use a persistant database.
  • Supports Cookie and Header Signing for integrity, and authenticity.
  • Supports Database Session Data Encryption for confidentiality, integrity.
  • Supports SessionID renewal for enhanced Security.
  • Optional Fastbloom key storage for reduced Database lookups during new UUID generation. Boosting Bandwidth.
  • Optional Rest Mode that Disables Cookies and uses the Header values instead.
  • uses #![forbid(unsafe_code)] to ensure everything is implemented as safe rust.
  • has an advanced API to allow further control of a session.
  • uses IP address's and user agent to deter spoofing of signed cookies and headers.

🚨 Help

If you need help with this library or have suggestions please go to our Discord Group

📦 Install

Axum Session uses tokio. to your cargo include for Axum Session.

# Cargo.toml
[dependencies]
# Postgres + rustls
axum_session = { version = "0.14.0" }

📱 Cargo Feature Flags

Features Description
advanced Enable functions allowing more direct control over the sessions.
rest_mode Disables Cookie Handlering In place of Header only usage for Rest API Requests and Responses.
key-store Enabled the optional key storage. Will increase ram usage based on Fastbloom settings.
Database Crate Persistent Description
axum_session_sqlx Yes Sqlx session store
axum_session_surreal Yes Surreal session store
axum_session_mongo Yes Mongo session store
axum_session_redispool Yes RedisPool session store

🔎 Example Default Setup

You can find examples within the Repository

use sqlx::{ConnectOptions, postgres::{PgPoolOptions, PgConnectOptions}};
use std::net::SocketAddr;
use axum_session::{Session, SessionPgPool, SessionConfig, SessionStore, SessionLayer};
use axum::{
    Router,
    routing::get,
};
use tokio::net::TcpListener;

#[tokio::main]
async fn main() {

    let poll = connect_to_database().await.unwrap();

    //This Defaults as normal Cookies.
    //To enable Private cookies for integrity, and authenticity please check the next Example.
    let session_config = SessionConfig::default()
        .with_table_name("sessions_table");

    // create SessionStore and initiate the database tables
    let session_store = SessionStore::<SessionPgPool>::new(Some(poll.clone().into()), session_config).await.unwrap();

    // build our application with some routes
    let app = Router::new()
        .route("/greet", get(greet))
        .layer(SessionLayer::new(session_store));

    // run it
    let addr = SocketAddr::from(([0, 0, 0, 0], 8000));

    println!("listening on {}", addr);
    let listener = TcpListener::bind(addr).await.unwrap();
    axum::serve(listener, app).await.unwrap();
}

async fn greet(session: Session<SessionPgPool>) -> String {
    let mut count: usize = session.get("count").unwrap_or(0);

    count += 1;
    session.set("count", count);

    count.to_string()
}

async fn connect_to_database() -> anyhow::Result<sqlx::Pool<sqlx::Postgres>> {
    // ...
    unimplemented!()
}

🔑 Key Store Details

To enable and use fastbloom key storage for less database lookups. Add the feature "key-store" to the crate’s features. This feature will increase the ram usage server side. but will heavily improve the bandwidth limitations and reduce latency of returns from the server. This is based on how much the filter_expected_elements and filter_false_positive_probability are set too. The higher they are the more ram is used. You will also need to Enable the bloom filter in the config for it to be used. By default, the use_bloom_filters is enabled and these config options exist whither or not the feature is enabled. Please refer to with_filter_expected_elements and with_filter_false_positive_probability within the documents to set the options. Otherwise stick with the default settings which should work in most situations. Just do note these options provide on how many False positives could possibly occur when comparing a UUID to what currently exists, which means it will keep trying till it finds none that match. Higher values decrease the chance of a false positive but increase ram usage.

😎 Session Login and Authentication via axum_session_auth

For user login, login caching and authentication please see axum_session_auth.

最近版本更新:(数据更新于 2024-10-02 19:19:47)

2024-04-13 03:01:13 v0.14.0

2024-02-05 23:49:36 v0.12.4

2024-01-13 07:06:31 v0.12.1

2023-12-21 22:28:48 v0.11.1

2023-12-12 20:55:49 v0.10.1

2023-11-27 23:51:19 v0.10.0

2023-11-14 02:48:25 v0.9.0

2023-10-24 02:09:18 v0.8.0

2023-10-04 23:23:27 v0.7.0

2023-09-19 04:09:47 v0.6.0

AscendingCreations/AxumSession同语言 Rust最近更新仓库

2024-12-22 08:48:41 lapce/lapce

2024-12-19 20:41:09 tw93/Pake

2024-12-19 19:31:32 dashpay/platform

2024-12-18 10:31:25 DioxusLabs/dioxus

2024-12-17 17:18:34 lanyeeee/jmcomic-downloader

2024-12-16 23:19:51 meilisearch/meilisearch