1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-23 15:51:06 +01:00

session, redis, and httpauth pre-v4 releases (#162)

This commit is contained in:
Rob Ede 2021-03-21 09:38:29 +00:00 committed by GitHub
parent 8d635f71fb
commit 5a72dd33d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 113 additions and 159 deletions

View File

@ -35,24 +35,9 @@ jobs:
profile: minimal
override: true
- name: tests (1.40.0)
if: matrix.version == '1.40.0'
- name: tests
uses: actions-rs/cargo@v1
timeout-minutes: 40
with:
command: test
args: --package=actix-cors
--package=actix-identity
--package=actix-redis
--package=actix-session
--package=actix-web-httpauth
--all-features --no-fail-fast -- --nocapture
- name: tests (1.42.0)
if: matrix.version == '1.42.0'
uses: actions-rs/cargo@v1
timeout-minutes: 40
with:
command: test
args: --package=actix-protobuf
--all-features --no-fail-fast -- --nocapture
args: --workspace --all-features --no-fail-fast -- --nocapture

View File

@ -3,7 +3,7 @@
> A collection of additional crates supporting the [actix-web] and [actix] frameworks.
[![build status](https://github.com/actix/actix-extras/workflows/CI%20%28Linux%29/badge.svg?branch=master&event=push)](https://github.com/actix/actix-extras/actions)
[![Join the chat at https://gitter.im/actix/actix-web](https://badges.gitter.im/actix/actix-web.svg)](https://gitter.im/actix/actix-web?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/5Ux4QGChWc)
## Crates by @actix

View File

@ -2,15 +2,14 @@
> Cross-origin resource sharing (CORS) for Actix Web.
[![crates.io](https://img.shields.io/crates/v/actix-cors)](https://crates.io/crates/actix-cors)
[![crates.io](https://img.shields.io/crates/v/actix-cors?label=latest)](https://crates.io/crates/actix-cors)
[![Documentation](https://docs.rs/actix-cors/badge.svg?version=0.5.4)](https://docs.rs/actix-cors/0.5.4)
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-cors)
[![Dependency Status](https://deps.rs/crate/actix-cors/0.5.4/status.svg)](https://deps.rs/crate/actix-cors/0.5.4)
[![Join the chat at https://gitter.im/actix/actix-web](https://badges.gitter.im/actix/actix-web.svg)](https://gitter.im/actix/actix-web?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
## Documentation & Resources
- [API Documentation](https://docs.rs/actix-cors/)
- [API Documentation](https://docs.rs/actix-cors)
- [Example Project](https://github.com/actix/examples/tree/master/security/web-cors)
- [Chat on Gitter](https://gitter.im/actix/actix-web)
- Minimum Supported Rust Version (MSRV): 1.42.0

View File

@ -16,4 +16,4 @@
* [API Documentation](https://docs.rs/actix-identity/)
* [Chat on gitter](https://gitter.im/actix/actix)
* Cargo package: [actix-identity](https://crates.io/crates/actix-identity)
* Minimum supported Rust version: 1.40 or later
* Minimum Supported Rust Version (MSRV): 1.42.0

View File

@ -8,7 +8,7 @@
> Protobuf support for actix-web framework.
* Minimum supported Rust version: 1.40.0 or later
* Minimum supported Rust version: 1.42.0 or later
## Example

View File

@ -1,11 +1,16 @@
# Changes
## Unreleased - 2020-xx-xx
## 0.9.2 - 2020-03-21
* Implement `std::error::Error` for `Error` [#135]
* Allow the removal of Max-Age for session-only cookies. [#161]
[#135]: https://github.com/actix/actix-extras/pull/135
[#161]: https://github.com/actix/actix-extras/pull/161
## 0.9.1 - 2020-09-12
* Enforce minimum redis-async version of 0.6.3 to workaround breaking patch change.

View File

@ -1,8 +1,8 @@
[package]
name = "actix-redis"
version = "0.9.1"
version = "0.9.2"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Redis integration for Actix web"
description = "Redis integration for Actix and session store for Actix Web"
license = "MIT OR Apache-2.0"
readme = "README.md"
keywords = ["actix", "redis", "async", "session"]
@ -38,10 +38,10 @@ actix-utils = "2.0.0"
log = "0.4.6"
backoff = "0.2.1"
derive_more = "0.99.2"
futures-util = { version = "0.3.5", default-features = false }
futures-util = { version = "0.3.7", default-features = false }
redis-async = "0.6.3"
actix-rt = "1.1.1"
time = "0.2.9"
time = "0.2.23"
tokio = "0.2.6"
tokio-util = "0.3.0"

View File

@ -1,21 +1,19 @@
# actix-redis
[![crates.io](https://img.shields.io/crates/v/actix-redis)](https://crates.io/crates/actix-redis)
[![Documentation](https://docs.rs/actix-redis/badge.svg)](https://docs.rs/actix-redis)
[![Dependency Status](https://deps.rs/crate/actix-redis/0.8.1/status.svg)](https://deps.rs/crate/actix-redis/0.8.1)
> Redis integration for Actix and session store for Actix Web.
[![crates.io](https://img.shields.io/crates/v/actix-redis?label=latest)](https://crates.io/crates/actix-redis)
[![Documentation](https://docs.rs/actix-redis/badge.svg?version=0.9.2)](https://docs.rs/actix-redis/0.9.2)
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-redis)
[![Join the chat at https://gitter.im/actix/actix](https://badges.gitter.im/actix/actix.svg)](https://gitter.im/actix/actix?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Dependency Status](https://deps.rs/crate/actix-redis/0.9.2/status.svg)](https://deps.rs/crate/actix-redis/0.9.2)
> Redis integration for actix framework.
## Documentation & Resources
## Documentation
- [API Documentation](https://docs.rs/actix-cors)
- [Example Project](https://github.com/actix/examples/tree/HEAD/session/redis-session)
- Minimum Supported Rust Version (MSRV): 1.42.0
* [API Documentation](https://actix.rs/actix-extras/actix_redis/)
* [Chat on gitter](https://gitter.im/actix/actix)
* Cargo package: [actix-redis](https://crates.io/crates/actix-redis)
* Minimum supported Rust version: 1.40 or later
## Redis session backend
## Redis Session Backend
Use redis as session storage.
@ -49,18 +47,3 @@ async fn main() -> std::io::Result {
.await
}
```
## License
This project is licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0))
* MIT license ([LICENSE-MIT](LICENSE-MIT) or [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT))
at your option.
## Code of Conduct
Contribution to the actix-redis crate is organized under the terms of the
Contributor Covenant, the maintainer of actix-redis, @fafhrd91, promises to
intervene to uphold that code of conduct.

View File

@ -1,11 +1,4 @@
//! Redis integration for Actix framework.
//!
//! ## Documentation
//! * [API Documentation (Development)](http://actix.github.io/actix-redis/actix_redis/)
//! * [API Documentation (Releases)](https://docs.rs/actix-redis/)
//! * [Chat on gitter](https://gitter.im/actix/actix)
//! * Cargo package: [actix-redis](https://crates.io/crates/actix-redis)
//! * Minimum supported Rust version: 1.40.0 or later
//! Redis integration for Actix and session store for Actix Web.
#![deny(rust_2018_idioms)]

View File

@ -43,62 +43,70 @@ impl RedisSession {
secure: false,
max_age: Some(Duration::days(7)),
same_site: None,
http_only: Some(true),
http_only: true,
}))
}
/// Set time to live in seconds for session value
/// Set time to live in seconds for session value.
pub fn ttl(mut self, ttl: u32) -> Self {
Rc::get_mut(&mut self.0).unwrap().ttl = format!("{}", ttl);
self
}
/// Set custom cookie name for session id
/// Set custom cookie name for session ID.
pub fn cookie_name(mut self, name: &str) -> Self {
Rc::get_mut(&mut self.0).unwrap().name = name.to_owned();
self
}
/// Set custom cookie path
/// Set custom cookie path.
pub fn cookie_path(mut self, path: &str) -> Self {
Rc::get_mut(&mut self.0).unwrap().path = path.to_owned();
self
}
/// Set custom cookie domain
/// Set custom cookie domain.
pub fn cookie_domain(mut self, domain: &str) -> Self {
Rc::get_mut(&mut self.0).unwrap().domain = Some(domain.to_owned());
self
}
/// Set custom cookie secure
/// Set custom cookie secure.
///
/// If the `secure` field is set, a cookie will only be transmitted when the
/// connection is secure - i.e. `https`
/// connection is secure - i.e. `https`.
///
/// Default is false.
pub fn cookie_secure(mut self, secure: bool) -> Self {
Rc::get_mut(&mut self.0).unwrap().secure = secure;
self
}
/// Set custom cookie max-age
/// Use `None` for session-only cookies
/// Set custom cookie max-age.
///
/// Use `None` for session-only cookies.
pub fn cookie_max_age(mut self, max_age: impl Into<Option<Duration>>) -> Self {
Rc::get_mut(&mut self.0).unwrap().max_age = max_age.into();
self
}
/// Set custom cookie SameSite
/// Set custom cookie `SameSite` attribute.
///
/// By default, the attribute is omitted.
pub fn cookie_same_site(mut self, same_site: SameSite) -> Self {
Rc::get_mut(&mut self.0).unwrap().same_site = Some(same_site);
self
}
/// Set custom cookie HttpOnly policy
/// Set custom cookie `HttpOnly` policy.
///
/// Default is true.
pub fn cookie_http_only(mut self, http_only: bool) -> Self {
Rc::get_mut(&mut self.0).unwrap().http_only = Some(http_only);
Rc::get_mut(&mut self.0).unwrap().http_only = http_only;
self
}
/// Set a custom cache key generation strategy, expecting session key as input
/// Set a custom cache key generation strategy, expecting session key as input.
pub fn cache_keygen(mut self, keygen: Box<dyn Fn(&str) -> String>) -> Self {
Rc::get_mut(&mut self.0).unwrap().cache_keygen = keygen;
self
@ -214,7 +222,7 @@ struct Inner {
secure: bool,
max_age: Option<Duration>,
same_site: Option<SameSite>,
http_only: Option<bool>,
http_only: bool,
}
impl Inner {
@ -293,7 +301,7 @@ impl Inner {
let mut cookie = Cookie::new(self.name.clone(), value.clone());
cookie.set_path(self.path.clone());
cookie.set_secure(self.secure);
cookie.set_http_only(self.http_only.unwrap_or(true));
cookie.set_http_only(self.http_only);
if let Some(ref domain) = self.domain {
cookie.set_domain(domain.clone());

View File

@ -1,8 +1,14 @@
# Changes
## Unreleased - 2020-xx-xx
* `Session::set_session` takes a `IntoIterator` instead of `Iterator`
* Fix calls to `session.purge()` from paths other than the one specified in the cookie
## 0.4.1 - 2020-03-21
* `Session::set_session` takes a `IntoIterator` instead of `Iterator`. [#105]
* Fix calls to `session.purge()` from paths other than the one specified in the cookie. [#129]
[#105]: https://github.com/actix/actix-extras/pull/105
[#129]: https://github.com/actix/actix-extras/pull/129
## 0.4.0 - 2020-09-11

View File

@ -1,6 +1,6 @@
[package]
name = "actix-session"
version = "0.4.0"
version = "0.4.1"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Sessions for Actix web"
readme = "README.md"
@ -23,10 +23,10 @@ cookie-session = ["actix-web/secure-cookies"]
actix-web = { version = "3.0.0", default_features = false }
actix-service = "1.0.6"
derive_more = "0.99.2"
futures-util = { version = "0.3.4", default-features = false }
futures-util = { version = "0.3.7", default-features = false }
serde = "1.0"
serde_json = "1.0"
time = { version = "0.2.7", default-features = false, features = ["std"] }
time = { version = "0.2.23", default-features = false, features = ["std"] }
[dev-dependencies]
actix-rt = "1"

View File

@ -1,19 +1,15 @@
# actix-session
[![crates.io](https://img.shields.io/crates/v/actix-session)](https://crates.io/crates/actix-session)
[![Documentation](https://docs.rs/actix-session/badge.svg)](https://docs.rs/actix-session)
[![Dependency Status](https://deps.rs/crate/actix-session/0.3.0/status.svg)](https://deps.rs/crate/actix-session/0.3.0)
[![Build Status](https://travis-ci.org/actix/actix-session.svg?branch=master)](https://travis-ci.org/actix/actix-session)
[![codecov](https://codecov.io/gh/actix/actix-session/branch/master/graph/badge.svg)](https://codecov.io/gh/actix/actix-session)
> Sessions for Actix Web.
[![crates.io](https://img.shields.io/crates/v/actix-session?label=latest)](https://crates.io/crates/actix-session)
[![Documentation](https://docs.rs/actix-session/badge.svg?version=0.4.1)](https://docs.rs/actix-session/0.4.1)
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-session)
[![Join the chat at https://gitter.im/actix/actix](https://badges.gitter.im/actix/actix.svg)](https://gitter.im/actix/actix?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Dependency Status](https://deps.rs/crate/actix-session/0.4.1/status.svg)](https://deps.rs/crate/actix-session/0.4.1)
> Session for actix-web framework.
## Documentation & community resources
## Documentation & Resources
* [User Guide](https://actix.rs/docs/)
* [API Documentation](https://docs.rs/actix-session/)
* [Chat on gitter](https://gitter.im/actix/actix)
* Cargo package: [actix-session](https://crates.io/crates/actix-session)
* Minimum supported Rust version: 1.40 or later
- [API Documentation](https://docs.rs/actix-session)
- [Example Projects](https://github.com/actix/examples/tree/HEAD/session)
- Minimum Supported Rust Version (MSRV): 1.42.0

View File

@ -1,19 +1,4 @@
//! Cookie session.
//!
//! [**CookieSession**](struct.CookieSession.html)
//! uses cookies as session storage. `CookieSession` creates sessions
//! which are limited to storing fewer than 4000 bytes of data, as the payload
//! must fit into a single cookie. An internal server error is generated if a
//! session contains more than 4000 bytes.
//!
//! A cookie may have a security policy of *signed* or *private*. Each has
//! a respective `CookieSession` constructor.
//!
//! A *signed* cookie may be viewed but not modified by the client. A *private*
//! cookie may neither be viewed nor modified by the client.
//!
//! The constructors take a key as an argument. This is the private key
//! for cookie session - when this value is changed, all session data is lost.
//! Cookie based sessions. See docs for [`CookieSession`].
use std::collections::HashMap;
use std::rc::Rc;
@ -180,7 +165,7 @@ impl CookieSessionInner {
/// than 4000 bytes.
///
/// A cookie may have a security policy of *signed* or *private*. Each has a
/// respective `CookieSessionBackend` constructor.
/// respective `CookieSession` constructor.
///
/// A *signed* cookie is stored on the client as plaintext alongside
/// a signature such that the cookie may be viewed but not modified by the
@ -198,9 +183,8 @@ impl CookieSessionInner {
/// By default all cookies are percent encoded, but certain symbols may
/// cause troubles when reading cookie, if they are not properly percent encoded.
///
/// # Example
///
/// ```rust
/// # Examples
/// ```
/// use actix_session::CookieSession;
/// use actix_web::{web, App, HttpResponse, HttpServer};
///
@ -215,7 +199,7 @@ impl CookieSessionInner {
pub struct CookieSession(Rc<CookieSessionInner>);
impl CookieSession {
/// Construct new *signed* `CookieSessionBackend` instance.
/// Construct new *signed* `CookieSession` instance.
///
/// Panics if key length is less than 32 bytes.
pub fn signed(key: &[u8]) -> CookieSession {
@ -225,7 +209,7 @@ impl CookieSession {
)))
}
/// Construct new *private* `CookieSessionBackend` instance.
/// Construct new *private* `CookieSession` instance.
///
/// Panics if key length is less than 32 bytes.
pub fn private(key: &[u8]) -> CookieSession {

View File

@ -1,18 +1,16 @@
//! User sessions.
//! Sessions for Actix Web.
//!
//! Actix provides a general solution for session management. Session
//! middlewares could provide different implementations which could
//! be accessed via general session api.
//! Provides a general solution for session management. Session middleware could provide different
//! implementations which could be accessed via general session API.
//!
//! By default, only cookie session backend is implemented. Other
//! backend implementations can be added.
//! This crate provides a general solution for session management and includes a cookie backend.
//! Other backend implementations can be built to use persistent or key-value stores, for example.
//!
//! In general, you insert a *session* middleware and initialize it
//! , such as a `CookieSessionBackend`. To access session data,
//! [*Session*](struct.Session.html) extractor must be used. Session
//! extractor allows us to get or set session data.
//! In general, some session middleware, such as a [`CookieSession`] is initialized and applied.
//! To access session data, the [`Session`] extractor must be used. This extractor allows reading
//! modifying session data.
//!
//! ```rust,no_run
//! ```no_run
//! use actix_web::{web, App, HttpServer, HttpResponse, Error};
//! use actix_session::{Session, CookieSession};
//!
@ -20,7 +18,7 @@
//! // access session data
//! if let Some(count) = session.get::<i32>("counter")? {
//! println!("SESSION value: {}", count);
//! session.set("counter", count+1)?;
//! session.set("counter", count + 1)?;
//! } else {
//! session.set("counter", 1)?;
//! }
@ -31,12 +29,11 @@
//! #[actix_rt::main]
//! async fn main() -> std::io::Result<()> {
//! HttpServer::new(
//! || App::new().wrap(
//! CookieSession::signed(&[0; 32]) // <- create cookie based session middleware
//! .secure(false)
//! )
//! .service(web::resource("/").to(|| HttpResponse::Ok())))
//! .bind("127.0.0.1:59880")?
//! || App::new()
//! // create cookie based session middleware
//! .wrap(CookieSession::signed(&[0; 32]).secure(false))
//! .default_service(web::to(|| HttpResponse::Ok())))
//! .bind(("127.0.0.1", 8080))?
//! .run()
//! .await
//! }
@ -44,17 +41,14 @@
#![deny(rust_2018_idioms)]
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use std::{cell::RefCell, collections::HashMap, rc::Rc};
use actix_web::dev::{
Extensions, Payload, RequestHead, ServiceRequest, ServiceResponse,
};
use actix_web::{Error, FromRequest, HttpMessage, HttpRequest};
use futures_util::future::{ok, Ready};
use serde::de::DeserializeOwned;
use serde::Serialize;
use serde::{de::DeserializeOwned, Serialize};
#[cfg(feature = "cookie-session")]
mod cookie;
@ -63,16 +57,14 @@ pub use crate::cookie::CookieSession;
/// The high-level interface you use to modify session data.
///
/// Session object could be obtained with
/// [`UserSession::get_session`](trait.UserSession.html#tymethod.get_session)
/// method. The `UserSession` trait is implemented for `HttpRequest`, `ServiceRequest`, and
/// `RequestHead`.
/// Session object is obtained with [`UserSession::get_session`]. The [`UserSession`] trait is
/// implemented for `HttpRequest`, `ServiceRequest`, and `RequestHead`.
///
/// ```rust
/// ```
/// use actix_session::Session;
/// use actix_web::*;
/// use actix_web::Result;
///
/// fn index(session: Session) -> Result<&'static str> {
/// async fn index(session: Session) -> Result<&'static str> {
/// // access session data
/// if let Some(count) = session.get::<i32>("counter")? {
/// session.set("counter", count + 1)?;
@ -82,11 +74,10 @@ pub use crate::cookie::CookieSession;
///
/// Ok("Welcome!")
/// }
/// # fn main() {}
/// ```
pub struct Session(Rc<RefCell<SessionInner>>);
/// Helper trait that allows to get session
/// Extraction of a [`Session`] object.
pub trait UserSession {
fn get_session(&self) -> Session;
}
@ -188,12 +179,10 @@ impl Session {
/// Values that match keys already existing on the session will be overwritten. Values should
/// already be JSON serialized.
///
/// # Example
///
/// # Examples
/// ```
/// # use actix_session::Session;
/// # use actix_web::test;
/// #
/// let mut req = test::TestRequest::default().to_srv_request();
///
/// Session::set_session(

View File

@ -1,9 +1,12 @@
# Changes
## Unreleased - 2020-xx-xx
## 0.5.1 - 2020-03-21
* Correct error handling when extracting auth details from request. [#128]
[#128]: https://github.com/actix/actix-web-httpauth/pull/128
[#128]: https://github.com/actix/actix-extras/pull/128
## 0.5.0 - 2020-09-11

View File

@ -1,6 +1,6 @@
[package]
name = "actix-web-httpauth"
version = "0.5.0"
version = "0.5.1"
authors = [
"svartalf <self@svartalf.info>",
"Yuki Okushi <huyuumi.dev@gmail.com>",
@ -22,7 +22,7 @@ path = "src/lib.rs"
[dependencies]
actix-web = { version = "3.0.0", default_features = false }
base64 = "0.13"
futures-util = { version = "0.3", default-features = false }
futures-util = { version = "0.3.7", default-features = false }
[dev-dependencies]
actix-cors = "0.5"

View File

@ -2,12 +2,15 @@
> HTTP authentication schemes for [actix-web](https://github.com/actix/actix-web).
[![crates.io](https://img.shields.io/crates/v/actix-web-httpauth)](https://crates.io/crates/actix-web-httpauth)
[![Documentation](https://docs.rs/actix-web-httpauth/badge.svg)](https://docs.rs/actix-web-httpauth)
[![Dependency Status](https://deps.rs/crate/actix-web-httpauth/0.5.0/status.svg)](https://deps.rs/crate/actix-web-httpauth/0.5.0)
[![crates.io](https://img.shields.io/crates/v/actix-web-httpauth?label=latest)](https://crates.io/crates/actix-web-httpauth)
[![Documentation](https://docs.rs/actix-web-httpauth/badge.svg?version=0.5.1)](https://docs.rs/actix-web-httpauth/0.5.1)
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-web-httpauth)
[![Join the chat at https://gitter.im/actix/actix-web](https://badges.gitter.im/actix/actix-web.svg)](https://gitter.im/actix/actix-web?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Dependency Status](https://deps.rs/crate/actix-web-httpauth/0.5.1/status.svg)](https://deps.rs/crate/actix-web-httpauth/0.5.1)
## Documentation & Resources
- [API Documentation](https://docs.rs/actix-cors)
- Minimum Supported Rust Version (MSRV): 1.42.0
## Features
- Typed [Authorization] and [WWW-Authenticate] headers