Skip to content

Commit 8b4e8ea

Browse files
committed
chore(actix-session): prepare release 0.9.0
1 parent 5ceb3c7 commit 8b4e8ea

File tree

10 files changed

+466
-244
lines changed

10 files changed

+466
-244
lines changed

actix-cors/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
//! async fn main() -> std::io::Result<()> {
2626
//! HttpServer::new(|| {
2727
//! let cors = Cors::default()
28-
//! .allowed_origin("https://www.rust-lang.org")
29-
//! .allowed_origin_fn(|origin, _req_head| {
30-
//! origin.as_bytes().ends_with(b".rust-lang.org")
31-
//! })
32-
//! .allowed_methods(vec!["GET", "POST"])
33-
//! .allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
34-
//! .allowed_header(http::header::CONTENT_TYPE)
35-
//! .max_age(3600);
28+
//! .allowed_origin("https://www.rust-lang.org")
29+
//! .allowed_origin_fn(|origin, _req_head| {
30+
//! origin.as_bytes().ends_with(b".rust-lang.org")
31+
//! })
32+
//! .allowed_methods(vec!["GET", "POST"])
33+
//! .allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
34+
//! .allowed_header(http::header::CONTENT_TYPE)
35+
//! .max_age(3600);
3636
//!
3737
//! App::new()
3838
//! .wrap(cors)

actix-identity/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ all-features = true
1919

2020
[dependencies]
2121
actix-service = "2"
22-
actix-session = "0.8"
22+
actix-session = "0.9"
2323
actix-utils = "3"
2424
actix-web = { version = "4", default-features = false, features = ["cookies", "secure-cookies"] }
2525

@@ -31,7 +31,7 @@ tracing = { version = "0.1.30", default-features = false, features = ["log"] }
3131
[dev-dependencies]
3232
actix-http = "3"
3333
actix-web = { version = "4", default-features = false, features = ["macros", "cookies", "secure-cookies"] }
34-
actix-session = { version = "0.8", features = ["redis-rs-session", "cookie-session"] }
34+
actix-session = { version = "0.9", features = ["redis-rs-session", "cookie-session"] }
3535

3636
env_logger = "0.10"
3737
reqwest = { version = "0.11", default-features = false, features = ["cookies", "json"] }

actix-identity/README.md

+90-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,94 @@
1111

1212
<!-- prettier-ignore-end -->
1313

14-
## Documentation & community resources
14+
<!-- cargo-rdme start -->
1515

16-
- [API Documentation](https://docs.rs/actix-identity)
17-
- Minimum Supported Rust Version (MSRV): 1.57
16+
Identity management for Actix Web.
17+
18+
`actix-identity` can be used to track identity of a user across multiple requests. It is built on top of HTTP sessions, via [`actix-session`](https://docs.rs/actix-session).
19+
20+
## Getting started
21+
22+
To start using identity management in your Actix Web application you must register [`IdentityMiddleware`] and `SessionMiddleware` as middleware on your `App`:
23+
24+
```rust
25+
use actix_web::{cookie::Key, App, HttpServer, HttpResponse};
26+
use actix_identity::IdentityMiddleware;
27+
use actix_session::{storage::RedisSessionStore, SessionMiddleware};
28+
29+
#[actix_web::main]
30+
async fn main() {
31+
// When using `Key::generate()` it is important to initialize outside of the
32+
// `HttpServer::new` closure. When deployed the secret key should be read from a
33+
// configuration file or environment variables.
34+
let secret_key = Key::generate();
35+
36+
let redis_store = RedisSessionStore::new("redis://127.0.0.1:6379")
37+
.await
38+
.unwrap();
39+
40+
HttpServer::new(move || {
41+
App::new()
42+
// Install the identity framework first.
43+
.wrap(IdentityMiddleware::default())
44+
// The identity system is built on top of sessions. You must install the session
45+
// middleware to leverage `actix-identity`. The session middleware must be mounted
46+
// AFTER the identity middleware: `actix-web` invokes middleware in the OPPOSITE
47+
// order of registration when it receives an incoming request.
48+
.wrap(SessionMiddleware::new(
49+
redis_store.clone(),
50+
secret_key.clone()
51+
))
52+
// Your request handlers [...]
53+
})
54+
}
55+
```
56+
57+
User identities can be created, accessed and destroyed using the [`Identity`] extractor in your request handlers:
58+
59+
```rust
60+
use actix_web::{get, post, HttpResponse, Responder, HttpRequest, HttpMessage};
61+
use actix_identity::Identity;
62+
use actix_session::storage::RedisSessionStore;
63+
64+
#[get("/")]
65+
async fn index(user: Option<Identity>) -> impl Responder {
66+
if let Some(user) = user {
67+
format!("Welcome! {}", user.id().unwrap())
68+
} else {
69+
"Welcome Anonymous!".to_owned()
70+
}
71+
}
72+
73+
#[post("/login")]
74+
async fn login(request: HttpRequest) -> impl Responder {
75+
// Some kind of authentication should happen here
76+
// e.g. password-based, biometric, etc.
77+
// [...]
78+
79+
// attach a verified user identity to the active session
80+
Identity::login(&request.extensions(), "User1".into()).unwrap();
81+
82+
HttpResponse::Ok()
83+
}
84+
85+
#[post("/logout")]
86+
async fn logout(user: Identity) -> impl Responder {
87+
user.logout();
88+
HttpResponse::Ok()
89+
}
90+
```
91+
92+
## Advanced configuration
93+
94+
By default, `actix-identity` does not automatically log out users. You can change this behaviour by customising the configuration for [`IdentityMiddleware`] via [`IdentityMiddleware::builder`].
95+
96+
In particular, you can automatically log out users who:
97+
98+
- have been inactive for a while (see [`IdentityMiddlewareBuilder::visit_deadline`];
99+
- logged in too long ago (see [`IdentityMiddlewareBuilder::login_deadline`]).
100+
101+
[`IdentityMiddlewareBuilder::visit_deadline`]: config::IdentityMiddlewareBuilder::visit_deadline
102+
[`IdentityMiddlewareBuilder::login_deadline`]: config::IdentityMiddlewareBuilder::login_deadline
103+
104+
<!-- cargo-rdme end -->

actix-identity/src/lib.rs

+93-87
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,96 @@
1-
//! Identity management for Actix Web.
2-
//!
3-
//! `actix-identity` can be used to track identity of a user across multiple requests. It is built
4-
//! on top of HTTP sessions, via [`actix-session`](https://docs.rs/actix-session).
5-
//!
6-
//! # Getting started
7-
//! To start using identity management in your Actix Web application you must register
8-
//! [`IdentityMiddleware`] and `SessionMiddleware` as middleware on your `App`:
9-
//!
10-
//! ```no_run
11-
//! # use actix_web::web;
12-
//! use actix_web::{cookie::Key, App, HttpServer, HttpResponse};
13-
//! use actix_identity::IdentityMiddleware;
14-
//! use actix_session::{storage::RedisSessionStore, SessionMiddleware};
15-
//!
16-
//! #[actix_web::main]
17-
//! async fn main() {
18-
//! let secret_key = Key::generate();
19-
//! let redis_store = RedisSessionStore::new("redis://127.0.0.1:6379")
20-
//! .await
21-
//! .unwrap();
22-
//!
23-
//! HttpServer::new(move || {
24-
//! App::new()
25-
//! // Install the identity framework first.
26-
//! .wrap(IdentityMiddleware::default())
27-
//! // The identity system is built on top of sessions. You must install the session
28-
//! // middleware to leverage `actix-identity`. The session middleware must be mounted
29-
//! // AFTER the identity middleware: `actix-web` invokes middleware in the OPPOSITE
30-
//! // order of registration when it receives an incoming request.
31-
//! .wrap(SessionMiddleware::new(
32-
//! redis_store.clone(),
33-
//! secret_key.clone()
34-
//! ))
35-
//! // Your request handlers [...]
36-
//! # .default_service(web::to(|| HttpResponse::Ok()))
37-
//! })
38-
//! # ;
39-
//! }
40-
//! ```
41-
//!
42-
//! User identities can be created, accessed and destroyed using the [`Identity`] extractor in your
43-
//! request handlers:
44-
//!
45-
//! ```no_run
46-
//! use actix_web::{get, post, HttpResponse, Responder, HttpRequest, HttpMessage};
47-
//! use actix_identity::Identity;
48-
//! use actix_session::storage::RedisSessionStore;
49-
//!
50-
//! #[get("/")]
51-
//! async fn index(user: Option<Identity>) -> impl Responder {
52-
//! if let Some(user) = user {
53-
//! format!("Welcome! {}", user.id().unwrap())
54-
//! } else {
55-
//! "Welcome Anonymous!".to_owned()
56-
//! }
57-
//! }
58-
//!
59-
//! #[post("/login")]
60-
//! async fn login(request: HttpRequest) -> impl Responder {
61-
//! // Some kind of authentication should happen here
62-
//! // e.g. password-based, biometric, etc.
63-
//! // [...]
64-
//!
65-
//! // attach a verified user identity to the active session
66-
//! Identity::login(&request.extensions(), "User1".into()).unwrap();
67-
//!
68-
//! HttpResponse::Ok()
69-
//! }
70-
//!
71-
//! #[post("/logout")]
72-
//! async fn logout(user: Identity) -> impl Responder {
73-
//! user.logout();
74-
//! HttpResponse::Ok()
75-
//! }
76-
//! ```
77-
//!
78-
//! # Advanced configuration
79-
//! By default, `actix-identity` does not automatically log out users. You can change this behaviour
80-
//! by customising the configuration for [`IdentityMiddleware`] via [`IdentityMiddleware::builder`].
81-
//!
82-
//! In particular, you can automatically log out users who:
83-
//! - have been inactive for a while (see [`IdentityMiddlewareBuilder::visit_deadline`];
84-
//! - logged in too long ago (see [`IdentityMiddlewareBuilder::login_deadline`]).
85-
//!
86-
//! [`IdentityMiddlewareBuilder::visit_deadline`]: config::IdentityMiddlewareBuilder::visit_deadline
87-
//! [`IdentityMiddlewareBuilder::login_deadline`]: config::IdentityMiddlewareBuilder::login_deadline
1+
/*!
2+
Identity management for Actix Web.
3+
4+
`actix-identity` can be used to track identity of a user across multiple requests. It is built
5+
on top of HTTP sessions, via [`actix-session`](https://docs.rs/actix-session).
6+
7+
# Getting started
8+
To start using identity management in your Actix Web application you must register
9+
[`IdentityMiddleware`] and `SessionMiddleware` as middleware on your `App`:
10+
11+
```no_run
12+
# use actix_web::web;
13+
use actix_web::{cookie::Key, App, HttpServer, HttpResponse};
14+
use actix_identity::IdentityMiddleware;
15+
use actix_session::{storage::RedisSessionStore, SessionMiddleware};
16+
17+
#[actix_web::main]
18+
async fn main() {
19+
// When using `Key::generate()` it is important to initialize outside of the
20+
// `HttpServer::new` closure. When deployed the secret key should be read from a
21+
// configuration file or environment variables.
22+
let secret_key = Key::generate();
23+
24+
let redis_store = RedisSessionStore::new("redis://127.0.0.1:6379")
25+
.await
26+
.unwrap();
27+
28+
HttpServer::new(move || {
29+
App::new()
30+
// Install the identity framework first.
31+
.wrap(IdentityMiddleware::default())
32+
// The identity system is built on top of sessions. You must install the session
33+
// middleware to leverage `actix-identity`. The session middleware must be mounted
34+
// AFTER the identity middleware: `actix-web` invokes middleware in the OPPOSITE
35+
// order of registration when it receives an incoming request.
36+
.wrap(SessionMiddleware::new(
37+
redis_store.clone(),
38+
secret_key.clone(),
39+
))
40+
// Your request handlers [...]
41+
# .default_service(web::to(|| HttpResponse::Ok()))
42+
})
43+
# ;
44+
}
45+
```
46+
47+
User identities can be created, accessed and destroyed using the [`Identity`] extractor in your
48+
request handlers:
49+
50+
```no_run
51+
use actix_web::{get, post, HttpResponse, Responder, HttpRequest, HttpMessage};
52+
use actix_identity::Identity;
53+
use actix_session::storage::RedisSessionStore;
54+
55+
#[get("/")]
56+
async fn index(user: Option<Identity>) -> impl Responder {
57+
if let Some(user) = user {
58+
format!("Welcome! {}", user.id().unwrap())
59+
} else {
60+
"Welcome Anonymous!".to_owned()
61+
}
62+
}
63+
64+
#[post("/login")]
65+
async fn login(request: HttpRequest) -> impl Responder {
66+
// Some kind of authentication should happen here
67+
// e.g. password-based, biometric, etc.
68+
// [...]
69+
70+
// attach a verified user identity to the active session
71+
Identity::login(&request.extensions(), "User1".into()).unwrap();
72+
73+
HttpResponse::Ok()
74+
}
75+
76+
#[post("/logout")]
77+
async fn logout(user: Identity) -> impl Responder {
78+
user.logout();
79+
HttpResponse::Ok()
80+
}
81+
```
82+
83+
# Advanced configuration
84+
By default, `actix-identity` does not automatically log out users. You can change this behaviour
85+
by customising the configuration for [`IdentityMiddleware`] via [`IdentityMiddleware::builder`].
86+
87+
In particular, you can automatically log out users who:
88+
- have been inactive for a while (see [`IdentityMiddlewareBuilder::visit_deadline`];
89+
- logged in too long ago (see [`IdentityMiddlewareBuilder::login_deadline`]).
90+
91+
[`IdentityMiddlewareBuilder::visit_deadline`]: config::IdentityMiddlewareBuilder::visit_deadline
92+
[`IdentityMiddlewareBuilder::login_deadline`]: config::IdentityMiddlewareBuilder::login_deadline
93+
*/
8894

8995
#![forbid(unsafe_code)]
9096
#![deny(rust_2018_idioms, nonstandard_style, missing_docs)]

actix-limitation/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ redis = { version = "0.24", default-features = false, features = ["tokio-comp"]
3232
time = "0.3"
3333

3434
# session
35-
actix-session = { version = "0.8", optional = true }
35+
actix-session = { version = "0.9", optional = true }
3636

3737
[dev-dependencies]
3838
actix-web = "4"

actix-session/CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
## 0.9.0
6+
57
- Remove use of `async-trait` on `SessionStore` trait.
68
- Minimum supported Rust version (MSRV) is now 1.75.
79

actix-session/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "actix-session"
3-
version = "0.8.0"
3+
version = "0.9.0"
44
authors = [
55
"Nikolay Kim <[email protected]>",
66
"Luca Palmieri <[email protected]>",

0 commit comments

Comments
 (0)