Skip to content

Commit 1193dd0

Browse files
committed
migration notice
1 parent 73bd0db commit 1193dd0

File tree

3 files changed

+10
-204
lines changed

3 files changed

+10
-204
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "axum-sessions"
3-
version = "0.5.0"
3+
version = "0.6.0"
44
description = "🥠 Cookie-based sessions for Axum via async-session."
55
edition = "2021"
66
homepage = "https://github.com/maxcountryman/axum-sessions"

README.md

Lines changed: 3 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,5 @@
1-
> [!IMPORTANT]
2-
> **Migrating to [`tower-sessions`](https://github.com/maxcountryman/tower-sessions)**
1+
> [!IMPORTANT] > **Migration to `tower-sessions`**
32
>
4-
> We have moved development of this crate to `tower-sessions`.
3+
> **Development of this crate has moved to [`tower-sessions`](https://github.com/maxcountryman/tower-sessions).** Please consider migrating.
54
>
6-
> Please **consider migrating** to `tower-sessions` if you use this crate.
7-
8-
<h1 align="center">
9-
axum-sessions
10-
</h1>
11-
12-
<p align="center">
13-
🥠 Cookie-based sessions for Axum via async-session.
14-
</p>
15-
16-
<div align="center">
17-
<a href="https://crates.io/crates/axum-sessions">
18-
<img src="https://img.shields.io/crates/v/axum-sessions.svg" />
19-
</a>
20-
<a href="https://docs.rs/axum-sessions">
21-
<img src="https://docs.rs/axum-sessions/badge.svg" />
22-
</a>
23-
<a href="https://github.com/maxcountryman/axum-sessions/actions/workflows/rust.yml">
24-
<img src="https://github.com/maxcountryman/axum-sessions/actions/workflows/rust.yml/badge.svg" />
25-
</a>
26-
<a href='https://coveralls.io/github/maxcountryman/axum-sessions?branch=main'>
27-
<img src='https://coveralls.io/repos/github/maxcountryman/axum-sessions/badge.svg?branch=main' alt='Coverage Status' />
28-
</a>
29-
</div>
30-
31-
## 🎨 Overview
32-
33-
`axum-sessions` is a middleware providing cookie-based sessions for `axum` applications.
34-
35-
- Cryptographically-signed cookies, ensuring integrity and authenticity
36-
- Wraps `async-session`, enabling flexible cookie storage (e.g. `async-sqlx-session`)
37-
- Convenient extractor-based API (i.e. `ReadableSession` and `WritableSession`)
38-
- Can be used as a generic Tower middleware
39-
40-
## 📦 Install
41-
42-
To use the crate in your project, add the following to your `Cargo.toml` file:
43-
44-
```toml
45-
[dependencies]
46-
axum-sessions = "0.5.0"
47-
```
48-
49-
## 🤸 Usage
50-
51-
`axum` applications can use the middleware via the session layer.
52-
53-
### `axum` Example
54-
55-
```rust
56-
use axum::{response::IntoResponse, routing::get, Router};
57-
use axum_sessions::{
58-
async_session::MemoryStore,
59-
extractors::{ReadableSession, WritableSession},
60-
SessionLayer,
61-
};
62-
use rand::Rng;
63-
64-
#[tokio::main]
65-
async fn main() {
66-
let store = MemoryStore::new();
67-
let secret = rand::thread_rng().gen::<[u8; 128]>();
68-
let session_layer = SessionLayer::new(store, &secret).with_secure(false);
69-
70-
async fn display_handler(session: ReadableSession) -> impl IntoResponse {
71-
let mut count = 0;
72-
count = session.get("count").unwrap_or(count);
73-
format!(
74-
"Count is: {}; visit /inc to increment and /reset to reset",
75-
count
76-
)
77-
}
78-
79-
async fn increment_handler(mut session: WritableSession) -> impl IntoResponse {
80-
let mut count = 1;
81-
count = session.get("count").map(|n: i32| n + 1).unwrap_or(count);
82-
session.insert("count", count).unwrap();
83-
format!("Count is: {}", count)
84-
}
85-
86-
async fn reset_handler(mut session: WritableSession) -> impl IntoResponse {
87-
session.destroy();
88-
"Count reset"
89-
}
90-
91-
let app = Router::new()
92-
.route("/", get(display_handler))
93-
.route("/inc", get(increment_handler))
94-
.route("/reset", get(reset_handler))
95-
.layer(session_layer);
96-
97-
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
98-
.serve(app.into_make_service())
99-
.await
100-
.unwrap();
101-
}
102-
```
103-
104-
You can find this [example][counter-example] as well as other example projects in the [example directory][examples].
105-
106-
## Session authentication via `axum-login`
107-
108-
For user session management and authentication and authorization specifically please see [`axum-login`](https://github.com/maxcountryman/axum-login).
109-
110-
See the [crate documentation][docs] for more usage information.
111-
112-
[counter-example]: https://github.com/maxcountryman/axum-sessions/tree/main/examples/counter
113-
[examples]: https://github.com/maxcountryman/axum-sessions/tree/main/examples
114-
[docs]: https://docs.rs/axum-sessions
5+
> Numerous bugs and a significant design flaw with `axum-sessions` are addressed with `tower-sessions`.

src/lib.rs

Lines changed: 6 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,11 @@
1-
//! axum-sessions is a middleware providing cookie-based sessions for axum
2-
//! applications.
1+
//! # **Migration to `tower-sessions`**
32
//!
4-
//! [`SessionLayer`] provides client sessions via [`async_session`]. Sessions
5-
//! are backed by cryptographically signed cookies. These cookies are generated
6-
//! when they're not found or are otherwise invalid. When a valid, known cookie
7-
//! is received in a request, the session is hydrated from this cookie. The
8-
//! middleware provides sessions via [`SessionHandle`]. Handlers use the
9-
//! [`ReadableSession`](crate::extractors::ReadableSession) and
10-
//! [`WritableSession`](crate::extractors::WritableSession) extractors to read
11-
//! from and write to sessions respectively.
3+
//! **Development of this crate has moved to
4+
//! [`tower-sessions`](https://github.com/maxcountryman/tower-sessions).** Please consider
5+
//! migrating.
126
//!
13-
//! # Example
14-
//!
15-
//! Using the middleware with axum is straightforward:
16-
//!
17-
//! ```rust,no_run
18-
//! use axum::{routing::get, Router};
19-
//! use axum_sessions::{
20-
//! async_session::MemoryStore, extractors::WritableSession, PersistencePolicy, SessionLayer,
21-
//! };
22-
//!
23-
//! #[tokio::main]
24-
//! async fn main() {
25-
//! let store = MemoryStore::new();
26-
//! let secret = b"..."; // MUST be at least 64 bytes!
27-
//! let session_layer = SessionLayer::new(store, secret);
28-
//!
29-
//! async fn handler(mut session: WritableSession) {
30-
//! session
31-
//! .insert("foo", 42)
32-
//! .expect("Could not store the answer.");
33-
//! }
34-
//!
35-
//! let app = Router::new().route("/", get(handler)).layer(session_layer);
36-
//!
37-
//! axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
38-
//! .serve(app.into_make_service())
39-
//! .await
40-
//! .unwrap();
41-
//! }
42-
//! ```
43-
//!
44-
//! This middleware may also be used as a generic Tower middleware by making use
45-
//! of the [`SessionHandle`] extension:
46-
//!
47-
//! ```rust
48-
//! use std::convert::Infallible;
49-
//!
50-
//! use axum::http::header::SET_COOKIE;
51-
//! use axum_sessions::{async_session::MemoryStore, SessionHandle, SessionLayer};
52-
//! use http::{Request, Response};
53-
//! use hyper::Body;
54-
//! use rand::Rng;
55-
//! use tower::{Service, ServiceBuilder, ServiceExt};
56-
//!
57-
//! async fn handle(request: Request<Body>) -> Result<Response<Body>, Infallible> {
58-
//! let session_handle = request.extensions().get::<SessionHandle>().unwrap();
59-
//! let session = session_handle.read().await;
60-
//! // Use the session as you'd like.
61-
//!
62-
//! Ok(Response::new(Body::empty()))
63-
//! }
64-
//!
65-
//! # #[tokio::main]
66-
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
67-
//! let store = MemoryStore::new();
68-
//! let secret = rand::thread_rng().gen::<[u8; 128]>();
69-
//! let session_layer = SessionLayer::new(store, &secret);
70-
//!
71-
//! let mut service = ServiceBuilder::new()
72-
//! .layer(session_layer)
73-
//! .service_fn(handle);
74-
//!
75-
//! let request = Request::builder().body(Body::empty()).unwrap();
76-
//!
77-
//! let response = service.ready().await?.call(request).await?;
78-
//!
79-
//! assert_eq!(
80-
//! response
81-
//! .headers()
82-
//! .get(SET_COOKIE)
83-
//! .unwrap()
84-
//! .to_str()
85-
//! .unwrap()
86-
//! .split("=")
87-
//! .collect::<Vec<_>>()[0],
88-
//! "sid"
89-
//! );
90-
//!
91-
//! # Ok(())
92-
//! # }
93-
//! ```
7+
//! Numerous bugs and a significant design flaw with `axum-sessions` are
8+
//! addressed with `tower-sessions`.
949
9510
#![deny(missing_docs)]
9611

0 commit comments

Comments
 (0)