mirror of
https://github.com/actix/actix-extras.git
synced 2025-02-22 10:23:18 +01:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
87ec5b4589
57
.github/workflows/ci-post-merge.yml
vendored
57
.github/workflows/ci-post-merge.yml
vendored
@ -1,8 +1,13 @@
|
||||
name: CI (post-merge)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
push: { branches: [master] }
|
||||
|
||||
permissions: { contents: read }
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build_and_test_linux_nightly:
|
||||
@ -27,39 +32,26 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install ${{ matrix.version }}
|
||||
uses: actions-rs/toolchain@v1
|
||||
- name: Install Rust (${{ matrix.version }})
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.version }}-${{ matrix.target.triple }}
|
||||
profile: minimal
|
||||
override: true
|
||||
toolchain: ${{ matrix.version }}
|
||||
|
||||
- name: Install cargo-hack
|
||||
uses: taiki-e/install-action@cargo-hack
|
||||
|
||||
- name: Generate Cargo.lock
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: generate-lockfile
|
||||
- name: Cache Dependencies
|
||||
uses: Swatinem/rust-cache@v2.1.0
|
||||
- uses: taiki-e/cache-cargo-install-action@v1
|
||||
with: { tool: cargo-hack }
|
||||
|
||||
- name: check minimal
|
||||
uses: actions-rs/cargo@v1
|
||||
with: { command: ci-min }
|
||||
run: cargo ci-min
|
||||
|
||||
- name: check minimal + examples
|
||||
uses: actions-rs/cargo@v1
|
||||
with: { command: ci-check-min-examples }
|
||||
run: cargo ci-check-min-examples
|
||||
|
||||
- name: check default
|
||||
uses: actions-rs/cargo@v1
|
||||
with: { command: ci-check }
|
||||
run: cargo ci-check
|
||||
|
||||
- name: tests
|
||||
uses: actions-rs/cargo@v1
|
||||
timeout-minutes: 40
|
||||
with: { command: ci-test }
|
||||
run: cargo ci-test
|
||||
|
||||
- name: Clear the cargo caches
|
||||
run: |
|
||||
@ -86,18 +78,13 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install ${{ matrix.version }}
|
||||
run: |
|
||||
rustup install ${{ matrix.version }}-${{ matrix.target.triple }}
|
||||
rustup override set ${{ matrix.version }}-${{ matrix.target.triple }}
|
||||
- name: Install Rust (${{ matrix.version }})
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.version }}
|
||||
|
||||
- name: Install cargo-hack
|
||||
uses: taiki-e/install-action@cargo-hack
|
||||
|
||||
- name: Generate Cargo.lock
|
||||
run: cargo generate-lockfile
|
||||
- name: Cache Dependencies
|
||||
uses: Swatinem/rust-cache@v2.1.0
|
||||
- uses: taiki-e/cache-cargo-install-action@v1
|
||||
with: { tool: cargo-hack }
|
||||
|
||||
- name: check minimal
|
||||
run: cargo ci-min
|
||||
|
64
.github/workflows/ci.yml
vendored
64
.github/workflows/ci.yml
vendored
@ -1,10 +1,14 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request: {}
|
||||
push: { branches: [master] }
|
||||
|
||||
permissions: { contents: read }
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build_and_test_linux:
|
||||
@ -14,7 +18,7 @@ jobs:
|
||||
target:
|
||||
- { name: Linux, os: ubuntu-latest, triple: x86_64-unknown-linux-gnu }
|
||||
version:
|
||||
- 1.59 # MSRV
|
||||
- '1.60' # MSRV
|
||||
- stable
|
||||
|
||||
name: ${{ matrix.target.name }} / ${{ matrix.version }}
|
||||
@ -35,18 +39,19 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install ${{ matrix.version }}
|
||||
run: |
|
||||
rustup install ${{ matrix.version }}-${{ matrix.target.triple }}
|
||||
rustup override set ${{ matrix.version }}-${{ matrix.target.triple }}
|
||||
- name: Install Rust (${{ matrix.version }})
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.version }}
|
||||
|
||||
- name: Install cargo-hack
|
||||
uses: taiki-e/install-action@cargo-hack
|
||||
uses: taiki-e/cache-cargo-install-action@v1
|
||||
with: { tool: cargo-hack }
|
||||
|
||||
- name: Generate Cargo.lock
|
||||
run: cargo generate-lockfile
|
||||
- name: Cache Dependencies
|
||||
uses: Swatinem/rust-cache@v2.1.0
|
||||
- name: workaround MSRV issues
|
||||
if: matrix.version != 'stable'
|
||||
run: |
|
||||
cargo update -p=time:0.3.20 --precise=0.3.16
|
||||
|
||||
- name: check minimal
|
||||
run: cargo ci-min
|
||||
@ -78,7 +83,7 @@ jobs:
|
||||
triple: x86_64-pc-windows-msvc,
|
||||
}
|
||||
version:
|
||||
- 1.59 # MSRV
|
||||
- '1.60' # MSRV
|
||||
- stable
|
||||
|
||||
name: ${{ matrix.target.name }} / ${{ matrix.version }}
|
||||
@ -87,18 +92,19 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install ${{ matrix.version }}
|
||||
run: |
|
||||
rustup install ${{ matrix.version }}-${{ matrix.target.triple }}
|
||||
rustup override set ${{ matrix.version }}-${{ matrix.target.triple }}
|
||||
- name: Install Rust (${{ matrix.version }})
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.version }}
|
||||
|
||||
- name: Install cargo-hack
|
||||
uses: taiki-e/install-action@cargo-hack
|
||||
uses: taiki-e/cache-cargo-install-action@v1
|
||||
with: { tool: cargo-hack }
|
||||
|
||||
- name: Generate Cargo.lock
|
||||
run: cargo generate-lockfile
|
||||
- name: Cache Dependencies
|
||||
uses: Swatinem/rust-cache@v2.1.0
|
||||
- name: workaround MSRV issues
|
||||
if: matrix.version != 'stable'
|
||||
run: |
|
||||
cargo update -p=time:0.3.20 --precise=0.3.16
|
||||
|
||||
- name: check minimal
|
||||
run: cargo ci-min
|
||||
@ -125,14 +131,8 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install Rust (nightly)
|
||||
run: |
|
||||
rustup install nightly
|
||||
rustup override set nightly
|
||||
|
||||
- name: Generate Cargo.lock
|
||||
run: cargo generate-lockfile
|
||||
- name: Cache Dependencies
|
||||
uses: Swatinem/rust-cache@v2.1.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with: { toolchain: nightly }
|
||||
|
||||
- name: doc tests
|
||||
timeout-minutes: 40
|
||||
|
24
.github/workflows/coverage.yml
vendored
24
.github/workflows/coverage.yml
vendored
@ -1,10 +1,13 @@
|
||||
# disabled because `cargo tarpaulin` currently segfaults
|
||||
|
||||
name: Coverage
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
push: { branches: [master] }
|
||||
|
||||
permissions: { contents: read }
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
coverage:
|
||||
@ -20,20 +23,15 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install stable
|
||||
run: |
|
||||
rustup override set stable
|
||||
rustup update stable
|
||||
|
||||
- name: Generate Cargo.lock
|
||||
run: cargo generate-lockfile
|
||||
- name: Cache Dependencies
|
||||
uses: Swatinem/rust-cache@v2.1.0
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with: { toolchain: nightly }
|
||||
|
||||
- name: Generate coverage file
|
||||
run: |
|
||||
cargo install cargo-tarpaulin --vers "^0.13"
|
||||
cargo tarpaulin --workspace --out Xml --verbose
|
||||
|
||||
- name: Upload to Codecov
|
||||
uses: codecov/codecov-action@v3
|
||||
with: { file: cobertura.xml }
|
||||
|
55
.github/workflows/lint.yml
vendored
55
.github/workflows/lint.yml
vendored
@ -1,8 +1,12 @@
|
||||
name: Lint
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
on: [pull_request]
|
||||
|
||||
permissions: { contents: read }
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
fmt:
|
||||
@ -10,11 +14,12 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install Rust
|
||||
run: |
|
||||
rustup override set nightly
|
||||
rustup update nightly
|
||||
rustup component add rustfmt
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
components: rustfmt
|
||||
|
||||
- name: Check with rustfmt
|
||||
run: cargo fmt --all -- --check
|
||||
|
||||
@ -24,9 +29,35 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install Rust
|
||||
run: |
|
||||
rustup override set stable
|
||||
rustup update stable
|
||||
rustup component add rustfmt
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with: { components: clippy }
|
||||
|
||||
- name: Check with Clippy
|
||||
run: cargo clippy --workspace --tests --all-features
|
||||
|
||||
public-api-diff:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout ${{ github.base_ref }}
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.base_ref }}
|
||||
|
||||
- name: checkout ${{ github.head_ref }}
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with: { toolchain: nightly }
|
||||
|
||||
- name: Install cargo-public-api
|
||||
uses: taiki-e/cache-cargo-install-action@v1
|
||||
with: { tool: cargo-public-api }
|
||||
|
||||
- name: generate API diff
|
||||
run: |
|
||||
for f in $(find -mindepth 2 -maxdepth 2 -name Cargo.toml); do
|
||||
|
||||
cargo public-api --manifest-path "$f" --all-features diff ${{ github.event.pull_request.base.sha }}..${{ github.sha }} >> /tmp/diff.txt
|
||||
done
|
||||
cat /tmp/diff.txt
|
||||
|
16
.github/workflows/upload-doc.yml
vendored
16
.github/workflows/upload-doc.yml
vendored
@ -1,8 +1,13 @@
|
||||
name: Upload Documentation
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
push: { branches: [master] }
|
||||
|
||||
permissions: { contents: write }
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@ -11,10 +16,9 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install Rust
|
||||
run: |
|
||||
rustup override set nightly
|
||||
rustup update nightly
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with: { toolchain: nightly }
|
||||
|
||||
- name: Build Docs
|
||||
run: cargo doc --workspace --all-features --no-deps
|
||||
|
@ -11,6 +11,11 @@ members = [
|
||||
"actix-web-httpauth",
|
||||
]
|
||||
|
||||
# TODO(MSRV 1.64)
|
||||
# [workspace.package]
|
||||
# edition = "2018"
|
||||
# rust-version = "1.60"
|
||||
|
||||
[patch.crates-io]
|
||||
actix-cors = { path = "./actix-cors" }
|
||||
actix-identity = { path = "./actix-identity" }
|
||||
|
32
README.md
32
README.md
@ -11,12 +11,12 @@
|
||||
|
||||
| Crate | | |
|
||||
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
|
||||
| [actix-cors] | [](https://crates.io/crates/actix-cors) [](https://deps.rs/crate/actix-cors/0.6.1) | Cross-Origin Resource Sharing (CORS) controls. |
|
||||
| [actix-identity] | [](https://crates.io/crates/actix-identity) [](https://deps.rs/crate/actix-identity/0.4.0) | Identity management. |
|
||||
| [actix-limitation] | [](https://crates.io/crates/actix-limitation) [](https://deps.rs/crate/actix-limitation/0.3.0) | Rate-limiting using a fixed window counter for arbitrary keys, backed by Redis. |
|
||||
| [actix-protobuf] | [](https://crates.io/crates/actix-protobuf) [](https://deps.rs/crate/actix-protobuf/0.8.0) | Protobuf payload extractor. |
|
||||
| [actix-cors] | [](https://crates.io/crates/actix-cors) [](https://deps.rs/crate/actix-cors/0.6.4) | Cross-Origin Resource Sharing (CORS) controls. |
|
||||
| [actix-identity] | [](https://crates.io/crates/actix-identity) [](https://deps.rs/crate/actix-identity/0.5.2) | Identity management. |
|
||||
| [actix-limitation] | [](https://crates.io/crates/actix-limitation) [](https://deps.rs/crate/actix-limitation/0.4.0) | Rate-limiting using a fixed window counter for arbitrary keys, backed by Redis. |
|
||||
| [actix-protobuf] | [](https://crates.io/crates/actix-protobuf) [](https://deps.rs/crate/actix-protobuf/0.9.0) | Protobuf payload extractor. |
|
||||
| [actix-redis] | [](https://crates.io/crates/actix-redis) [](https://deps.rs/crate/actix-redis/0.12.0) | Actor-based Redis client. |
|
||||
| [actix-session] | [](https://crates.io/crates/actix-session) [](https://deps.rs/crate/actix-session/0.7.1) | Session management. |
|
||||
| [actix-session] | [](https://crates.io/crates/actix-session) [](https://deps.rs/crate/actix-session/0.7.2) | Session management. |
|
||||
| [actix-settings] | [](https://crates.io/crates/actix-settings) [](https://deps.rs/crate/actix-settings/0.6.0) | Easily manage Actix Web's settings from a TOML file and environment variables. |
|
||||
| [actix-web-httpauth] | [](https://crates.io/crates/actix-web-httpauth) [](https://deps.rs/crate/actix-web-httpauth/0.8.0) | HTTP authentication schemes. |
|
||||
|
||||
@ -28,21 +28,22 @@ These crates are provided by the community.
|
||||
|
||||
| Crate | | |
|
||||
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
|
||||
| [actix-web-lab] | [][actix-web-lab] [](https://deps.rs/crate/actix-web-lab/0.16.4) | Experimental extractors, middleware, and other extras for possible inclusion in Actix Web. |
|
||||
| [actix-multipart-extract] | [][actix-multipart-extract] [](https://deps.rs/crate/actix-multipart-extract/0.1.4) | Better multipart form support for Actix Web. |
|
||||
| [actix-form-data] | [][actix-form-data] [](https://deps.rs/crate/actix-form-data/0.6.2) | Rate-limiting backed by form-data. |
|
||||
| [actix-governor] | [][actix-governor] [](https://deps.rs/crate/actix-governor/0.3.0) | Rate-limiting backed by governor. |
|
||||
| [actix-web-lab] | [][actix-web-lab] [](https://deps.rs/crate/actix-web-lab/0.19.1) | Experimental extractors, middleware, and other extras for possible inclusion in Actix Web. |
|
||||
| [actix-multipart-extract] | [][actix-multipart-extract] [](https://deps.rs/crate/actix-multipart-extract/0.1.5) | Better multipart form support for Actix Web. |
|
||||
| [actix-form-data] | [][actix-form-data] [](https://deps.rs/crate/actix-form-data/0.7.0-beta.0) | Multipart form data from actix multipart streams |
|
||||
| [actix-governor] | [][actix-governor] [](https://deps.rs/crate/actix-governor/0.4.0) | Rate-limiting backed by governor. |
|
||||
| [actix-casbin] | [][actix-casbin] [](https://deps.rs/crate/actix-casbin/0.4.2) | Authorization library that supports access control models like ACL, RBAC & ABAC. |
|
||||
| [actix-ip-filter] | [][actix-ip-filter] [](https://deps.rs/crate/actix-ip-filter/0.3.1) | IP address filter. Supports glob patterns. |
|
||||
| [actix-web-static-files] | [][actix-web-static-files] [](https://deps.rs/crate/actix-web-static-files/4.0.0) | Static files as embedded resources. |
|
||||
| [actix-web-static-files] | [][actix-web-static-files] [](https://deps.rs/crate/actix-web-static-files/4.0.1) | Static files as embedded resources. |
|
||||
| [actix-web-grants] | [][actix-web-grants] [](https://deps.rs/crate/actix-web-grants/3.0.1) | Extension for validating user authorities. |
|
||||
| [aliri_actix] | [][aliri_actix] [](https://deps.rs/crate/aliri_actix/0.7.0) | Endpoint authorization and authentication using scoped OAuth2 JWT tokens. |
|
||||
| [actix-web-flash-messages] | [][actix-web-flash-messages] [](https://deps.rs/crate/actix-web-flash-messages/0.4.1) | Support for flash messages/one-time notifications in `actix-web`. |
|
||||
| [aliri_actix] | [][aliri_actix] [](https://deps.rs/crate/aliri_actix/0.8.0) | Endpoint authorization and authentication using scoped OAuth2 JWT tokens. |
|
||||
| [actix-web-flash-messages] | [][actix-web-flash-messages] [](https://deps.rs/crate/actix-web-flash-messages/0.4.2) | Support for flash messages/one-time notifications in `actix-web`. |
|
||||
| [awmp] | [][awmp] [](https://deps.rs/crate/awmp/0.8.1) | An easy to use wrapper around multipart fields for Actix Web. |
|
||||
| [tracing-actix-web] | [][tracing-actix-web] [](https://deps.rs/crate/tracing-actix-web/0.6.0) | A middleware to collect telemetry data from applications built on top of the actix-web framework. |
|
||||
| [tracing-actix-web] | [][tracing-actix-web] [](https://deps.rs/crate/tracing-actix-web/0.7.3) | A middleware to collect telemetry data from applications built on top of the actix-web framework. |
|
||||
| [actix-ws] | [][actix-ws] [](https://deps.rs/crate/actix-ws/0.2.5) | Actor-less WebSockets for the Actix Runtime. |
|
||||
| [actix-hash] | [][actix-hash] [](https://deps.rs/crate/actix-hash/0.4.0) | Hashing utilities for Actix Web. |
|
||||
| [actix-bincode] |  [](https://deps.rs/crate/actix-bincode/0.2.0) | Bincode payload extractor for Actix Web |
|
||||
| [actix-hash] | [][actix-hash] [](https://deps.rs/crate/actix-hash/0.5.0) | Hashing utilities for Actix Web. |
|
||||
| [actix-bincode] |  [](https://deps.rs/crate/actix-bincode/0.2.1) | Bincode payload extractor for Actix Web |
|
||||
| [sentinel-actix] |  [](https://deps.rs/crate/sentinel-actix/0.1.0) | General and flexible protection for Actix Web |
|
||||
|
||||
To add a crate to this list, submit a pull request.
|
||||
|
||||
@ -74,3 +75,4 @@ To add a crate to this list, submit a pull request.
|
||||
[actix-ws]: https://crates.io/crates/actix-ws
|
||||
[actix-hash]: https://crates.io/crates/actix-hash
|
||||
[actix-bincode]: https://crates.io/crates/actix-bincode
|
||||
[sentinel-actix]: https://crates.io/crates/sentinel-actix
|
||||
|
@ -2,76 +2,79 @@
|
||||
|
||||
## Unreleased - 2022-xx-xx
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.60.
|
||||
|
||||
## 0.6.4 - 2022-10-28
|
||||
|
||||
- Add `Cors::allow_private_network_access()` behind an unstable flag (`draft-private-network-access`). [#297]
|
||||
|
||||
[#297]: https://github.com/actix/actix-extras/pull/297
|
||||
|
||||
|
||||
## 0.6.3 - 2022-09-21
|
||||
|
||||
- Add `Cors::block_on_origin_mismatch()` option for controlling if requests are pre-emptively rejected. [#287]
|
||||
- Minimum supported Rust version (MSRV) is now 1.59 due to transitive `time` dependency.
|
||||
|
||||
[#287]: https://github.com/actix/actix-extras/pull/287
|
||||
|
||||
|
||||
## 0.6.2 - 2022-08-07
|
||||
|
||||
- Fix `expose_any_header` to return list of response headers. [#273]
|
||||
- Minimum supported Rust version (MSRV) is now 1.57 due to transitive `time` dependency.
|
||||
|
||||
[#273]: https://github.com/actix/actix-extras/pull/273
|
||||
|
||||
|
||||
## 0.6.1 - 2022-03-07
|
||||
|
||||
- Do not consider requests without a `Access-Control-Request-Method` as preflight. [#226]
|
||||
|
||||
[#226]: https://github.com/actix/actix-extras/pull/226
|
||||
|
||||
|
||||
## 0.6.0 - 2022-02-25
|
||||
|
||||
- Update `actix-web` dependency to 4.0.
|
||||
|
||||
## 0.6.0-beta.10 - 2022-02-07
|
||||
|
||||
- Ensure that preflight responses contain a `Vary` header. [#224]
|
||||
|
||||
[#224]: https://github.com/actix/actix-extras/pull/224
|
||||
|
||||
|
||||
## 0.6.0-beta.9 - 2022-02-07
|
||||
|
||||
- Relax body type bounds on middleware impl. [#223]
|
||||
- Update `actix-web` dependency to `4.0.0-rc.1`.
|
||||
|
||||
[#223]: https://github.com/actix/actix-extras/pull/223
|
||||
|
||||
|
||||
## 0.6.0-beta.8 - 2021-12-29
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.54.
|
||||
|
||||
|
||||
## 0.6.0-beta.7 - 2021-12-18
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0-beta.15`. [#216]
|
||||
|
||||
[#216]: https://github.com/actix/actix-extras/pull/216
|
||||
|
||||
|
||||
## 0.6.0-beta.6 - 2021-12-13
|
||||
|
||||
- Fix panic when wrapping routes with dynamic segments in their paths. [#213]
|
||||
|
||||
[#213]: https://github.com/actix/actix-extras/pull/213
|
||||
|
||||
|
||||
## 0.6.0-beta.5 - 2021-12-12 _(YANKED)_
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0.beta-14`. [#209]
|
||||
|
||||
[#209]: https://github.com/actix/actix-extras/pull/209
|
||||
|
||||
|
||||
## 0.6.0-beta.4 - 2021-11-22
|
||||
|
||||
- No significant changes since `0.6.0-beta.3`.
|
||||
|
||||
|
||||
## 0.6.0-beta.3 - 2021-10-21
|
||||
|
||||
- Make `Cors` middleware generic over body type [#195]
|
||||
- Fix `expose_any_header` behavior. [#204]
|
||||
- Update `actix-web` dependency to v4.0.0-beta.10. [#203]
|
||||
@ -81,38 +84,38 @@
|
||||
[#203]: https://github.com/actix/actix-extras/pull/203
|
||||
[#204]: https://github.com/actix/actix-extras/pull/204
|
||||
|
||||
|
||||
## 0.6.0-beta.2 - 2021-06-27
|
||||
|
||||
- No notable changes.
|
||||
|
||||
|
||||
## 0.6.0-beta.1 - 2021-04-02
|
||||
|
||||
- Update `actix-web` dependency to 4.0.0 beta.
|
||||
- Minimum supported Rust version (MSRV) is now 1.46.0.
|
||||
|
||||
|
||||
## 0.5.4 - 2020-12-31
|
||||
|
||||
- Fix `expose_any_header` method, now set the correct field. [#143]
|
||||
|
||||
[#143]: https://github.com/actix/actix-extras/pull/143
|
||||
|
||||
|
||||
## 0.5.3 - 2020-11-19
|
||||
|
||||
- Fix version spec for `derive_more` dependency.
|
||||
|
||||
|
||||
## 0.5.2 - 2020-11-15
|
||||
|
||||
- Ensure `tinyvec` is using the correct features.
|
||||
- Bump `futures-util` minimum version to `0.3.7` to avoid `RUSTSEC-2020-0059`.
|
||||
|
||||
|
||||
## 0.5.1 - 2020-11-05
|
||||
|
||||
- Fix `allow_any_header` method, now set the correct field. [#121]
|
||||
|
||||
[#121]: https://github.com/actix/actix-extras/pull/121
|
||||
|
||||
|
||||
## 0.5.0 - 2020-10-19
|
||||
|
||||
- Disallow `*` in `Cors::allowed_origin`. [#114].
|
||||
- Hide `CorsMiddleware` from docs. [#118].
|
||||
- `CorsFactory` is removed. [#119]
|
||||
@ -131,40 +134,40 @@
|
||||
[#119]: https://github.com/actix/actix-extras/pull/119
|
||||
[#120]: https://github.com/actix/actix-extras/pull/120
|
||||
|
||||
|
||||
## 0.4.1 - 2020-10-07
|
||||
|
||||
- Allow closures to be used with `allowed_origin_fn`. [#110]
|
||||
|
||||
[#110]: https://github.com/actix/actix-extras/pull/110
|
||||
|
||||
|
||||
## 0.4.0 - 2020-09-27
|
||||
|
||||
- Implement `allowed_origin_fn` builder method. [#93]
|
||||
- Use `TryInto` instead of `TryFrom` where applicable. [#106]
|
||||
|
||||
[#93]: https://github.com/actix/actix-extras/pull/93
|
||||
[#106]: https://github.com/actix/actix-extras/pull/106
|
||||
|
||||
|
||||
## 0.3.0 - 2020-09-11
|
||||
|
||||
- Update `actix-web` dependency to 3.0.0.
|
||||
- Minimum supported Rust version (MSRV) is now 1.42.0.
|
||||
- Implement the Debug trait on all public types.
|
||||
|
||||
|
||||
## 0.3.0-alpha.1 - 2020-03-11
|
||||
|
||||
- Minimize `futures-*` dependencies
|
||||
- Update `actix-web` dependency to 3.0.0-alpha.1
|
||||
|
||||
|
||||
## 0.2.0 - 2019-12-20
|
||||
|
||||
- Release
|
||||
|
||||
|
||||
## 0.2.0-alpha.3 - 2019-12-07
|
||||
|
||||
- Migrate to actix-web 2.0.0
|
||||
- Bump `derive_more` crate version to 0.99.0
|
||||
|
||||
|
||||
## 0.1.0 - 2019-06-15
|
||||
|
||||
- Move cors middleware to separate crate
|
||||
|
@ -11,6 +11,7 @@ homepage = "https://actix.rs"
|
||||
repository = "https://github.com/actix/actix-extras.git"
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2018"
|
||||
rust-version = "1.60"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
@ -23,13 +24,13 @@ draft-private-network-access = []
|
||||
actix-utils = "3"
|
||||
actix-web = { version = "4", default-features = false }
|
||||
|
||||
derive_more = "0.99.5"
|
||||
derive_more = "0.99.7"
|
||||
futures-util = { version = "0.3.7", default-features = false }
|
||||
log = "0.4"
|
||||
once_cell = "1"
|
||||
smallvec = "1.6.1"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-web = { version = "4", default_features = false, features = ["macros"] }
|
||||
env_logger = "0.9"
|
||||
actix-web = { version = "4", default-features = false, features = ["macros"] }
|
||||
env_logger = "0.10"
|
||||
regex = "1.4"
|
||||
|
@ -431,7 +431,6 @@ impl Cors {
|
||||
///
|
||||
/// [Private Network Access]: https://wicg.github.io/private-network-access
|
||||
#[cfg(feature = "draft-private-network-access")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "draft-private-network-access")))]
|
||||
pub fn allow_private_network_access(mut self) -> Cors {
|
||||
if let Some(cors) = cors(&mut self.inner, &self.error) {
|
||||
cors.allow_private_network_access = true;
|
||||
|
@ -8,8 +8,8 @@
|
||||
//!
|
||||
//! # Crate Features
|
||||
//! - `draft-private-network-access`: ⚠️ Unstable. Adds opt-in support for the [Private Network
|
||||
//! Access] spec extensions. This feature is unstable since it will follow any breaking changes in
|
||||
//! the draft spec until it is finalized.
|
||||
//! Access] spec extensions. This feature is unstable since it will follow breaking changes in the
|
||||
//! draft spec until it is finalized.
|
||||
//!
|
||||
//! # Example
|
||||
//! ```no_run
|
||||
@ -53,7 +53,7 @@
|
||||
#![warn(future_incompatible, missing_docs, missing_debug_implementations)]
|
||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
|
||||
mod all_or_some;
|
||||
mod builder;
|
||||
|
@ -149,7 +149,6 @@ impl<S> CorsMiddleware<S> {
|
||||
let expose_all_request_headers = res
|
||||
.headers()
|
||||
.keys()
|
||||
.into_iter()
|
||||
.map(|name| name.as_str())
|
||||
.collect::<HashSet<_>>();
|
||||
|
||||
|
@ -1,22 +1,26 @@
|
||||
# Changes
|
||||
|
||||
## Unreleased - 2022-xx-xx
|
||||
- Minimum supported Rust version (MSRV) is now 1.59 due to transitive `time` dependency.
|
||||
|
||||
- Replace use of `anyhow::Error` with specific error types. [#296]
|
||||
- Minimum supported Rust version (MSRV) is now 1.60.
|
||||
|
||||
[#296]: https://github.com/actix/actix-extras/pull/296
|
||||
|
||||
## 0.5.2 - 2022-07-19
|
||||
|
||||
- Fix visit deadline. [#263]
|
||||
|
||||
[#263]: https://github.com/actix/actix-extras/pull/263
|
||||
|
||||
|
||||
## 0.5.1 - 2022-07-11
|
||||
|
||||
- Remove unnecessary dependencies. [#259]
|
||||
|
||||
[#259]: https://github.com/actix/actix-extras/pull/259
|
||||
|
||||
|
||||
## 0.5.0 - 2022-07-11
|
||||
|
||||
`actix-identity` v0.5 is a complete rewrite. The goal is to streamline user experience and reduce maintenance overhead.
|
||||
|
||||
`actix-identity` is now designed as an additional layer on top of `actix-session` v0.7, focused on identity management. The identity information is stored in the session state, which is managed by `actix-session` and can be stored using any of the supported `SessionStore` implementations. This reduces the surface area in `actix-identity` (e.g., it is no longer concerned with cookies!) and provides a smooth upgrade path for users: if you need to work with sessions, you no longer need to choose between `actix-session` and `actix-identity`; they work together now!
|
||||
@ -29,9 +33,9 @@ Changes:
|
||||
- `IdentityService`, `IdentityPolicy` and `CookieIdentityPolicy` have been replaced by `IdentityMiddleware`. [#246]
|
||||
- Rename `RequestIdentity` trait to `IdentityExt`. [#246]
|
||||
- Trying to extract an `Identity` for an unauthenticated user will return a `401 Unauthorized` response to the client. Extract an `Option<Identity>` or a `Result<Identity, actix_web::Error>` if you need to handle cases where requests may or may not be authenticated. [#246]
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
```rust
|
||||
use actix_web::{http::header::LOCATION, get, HttpResponse, Responder};
|
||||
use actix_identity::Identity;
|
||||
@ -51,57 +55,57 @@ Changes:
|
||||
|
||||
[#246]: https://github.com/actix/actix-extras/pull/246
|
||||
|
||||
|
||||
## 0.4.0 - 2022-03-01
|
||||
|
||||
- Update `actix-web` dependency to `4`.
|
||||
|
||||
|
||||
## 0.4.0-beta.9 - 2022-02-07
|
||||
|
||||
- Relax body type bounds on middleware impl. [#223]
|
||||
- Update `actix-web` dependency to `4.0.0-rc.1`.
|
||||
|
||||
[#223]: https://github.com/actix/actix-extras/pull/223
|
||||
|
||||
|
||||
## 0.4.0-beta.8 - 2022-01-21
|
||||
|
||||
- No significant changes since `0.4.0-beta.7`.
|
||||
|
||||
|
||||
## 0.4.0-beta.7 - 2021-12-29
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0.beta-18`. [#218]
|
||||
- Minimum supported Rust version (MSRV) is now 1.54.
|
||||
|
||||
[#218]: https://github.com/actix/actix-extras/pull/218
|
||||
|
||||
|
||||
## 0.4.0-beta.6 - 2021-12-18
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0.beta-15`. [#216]
|
||||
|
||||
[#216]: https://github.com/actix/actix-extras/pull/216
|
||||
|
||||
|
||||
## 0.4.0-beta.5 - 2021-12-12
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0.beta-14`. [#209]
|
||||
|
||||
[#209]: https://github.com/actix/actix-extras/pull/209
|
||||
|
||||
|
||||
## 0.4.0-beta.4 - 2021-11-22
|
||||
|
||||
- No significant changes since `0.4.0-beta.3`.
|
||||
|
||||
|
||||
## 0.4.0-beta.3 - 2021-10-21
|
||||
|
||||
- Update `actix-web` dependency to v4.0.0-beta.10. [#203]
|
||||
- Minimum supported Rust version (MSRV) is now 1.52.
|
||||
|
||||
[#203]: https://github.com/actix/actix-extras/pull/203
|
||||
|
||||
|
||||
## 0.4.0-beta.2 - 2021-06-27
|
||||
|
||||
- No notable changes.
|
||||
|
||||
|
||||
## 0.4.0-beta.1 - 2021-04-02
|
||||
|
||||
- Rename `CookieIdentityPolicy::{max_age => max_age_secs}`. [#168]
|
||||
- Rename `CookieIdentityPolicy::{max_age_time => max_age}`. [#168]
|
||||
- Update `actix-web` dependency to 4.0.0 beta.
|
||||
@ -109,31 +113,31 @@ Changes:
|
||||
|
||||
[#168]: https://github.com/actix/actix-extras/pull/168
|
||||
|
||||
|
||||
## 0.3.1 - 2020-09-20
|
||||
|
||||
- Add method to set `HttpOnly` flag on cookie identity. [#102]
|
||||
|
||||
[#102]: https://github.com/actix/actix-extras/pull/102
|
||||
|
||||
|
||||
## 0.3.0 - 2020-09-11
|
||||
|
||||
- Update `actix-web` dependency to 3.0.0.
|
||||
- Minimum supported Rust version (MSRV) is now 1.42.0.
|
||||
|
||||
|
||||
## 0.3.0-alpha.1 - 2020-03-14
|
||||
|
||||
- Update the `time` dependency to 0.2.7
|
||||
- Update the `actix-web` dependency to 3.0.0-alpha.1
|
||||
- Minimize `futures` dependency
|
||||
|
||||
|
||||
## 0.2.1 - 2020-01-10
|
||||
|
||||
- Fix panic with already borrowed: BorrowMutError #1263
|
||||
|
||||
|
||||
## 0.2.0 - 2019-12-20
|
||||
|
||||
- Use actix-web 2.0
|
||||
|
||||
|
||||
## 0.1.0 - 2019-06-xx
|
||||
|
||||
- Move identity middleware to separate crate
|
||||
|
@ -11,10 +11,11 @@ homepage = "https://actix.rs"
|
||||
repository = "https://github.com/actix/actix-extras.git"
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2018"
|
||||
rust-version = "1.60"
|
||||
|
||||
[lib]
|
||||
name = "actix_identity"
|
||||
path = "src/lib.rs"
|
||||
[package.metadata.docs.rs]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
all-features = true
|
||||
|
||||
[dependencies]
|
||||
actix-service = "2"
|
||||
@ -22,16 +23,16 @@ actix-session = "0.7"
|
||||
actix-utils = "3"
|
||||
actix-web = { version = "4", default-features = false, features = ["cookies", "secure-cookies"] }
|
||||
|
||||
anyhow = "1"
|
||||
derive_more = "0.99.7"
|
||||
futures-core = "0.3.7"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-http = "3"
|
||||
actix-web = { version = "4", default_features = false, features = ["macros", "cookies", "secure-cookies"] }
|
||||
actix-web = { version = "4", default-features = false, features = ["macros", "cookies", "secure-cookies"] }
|
||||
actix-session = { version = "0.7", features = ["redis-rs-session", "cookie-session"] }
|
||||
|
||||
env_logger = "0.9"
|
||||
reqwest = { version = "0.11", default_features = false, features = ["cookies", "json"] }
|
||||
env_logger = "0.10"
|
||||
reqwest = { version = "0.11", default-features = false, features = ["cookies", "json"] }
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
|
70
actix-identity/src/error.rs
Normal file
70
actix-identity/src/error.rs
Normal file
@ -0,0 +1,70 @@
|
||||
//! Failure modes of identity operations.
|
||||
|
||||
use actix_session::{SessionGetError, SessionInsertError};
|
||||
use actix_web::{cookie::time::error::ComponentRange, http::StatusCode, ResponseError};
|
||||
use derive_more::{Display, Error, From};
|
||||
|
||||
/// Error that can occur during login attempts.
|
||||
#[derive(Debug, Display, Error, From)]
|
||||
#[display(fmt = "{_0}")]
|
||||
pub struct LoginError(SessionInsertError);
|
||||
|
||||
impl ResponseError for LoginError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
StatusCode::UNAUTHORIZED
|
||||
}
|
||||
}
|
||||
|
||||
/// Error encountered when working with a session that has expired.
|
||||
#[derive(Debug, Display, Error)]
|
||||
#[display(fmt = "The given session has expired and is no longer valid")]
|
||||
pub struct SessionExpiryError(#[error(not(source))] pub(crate) ComponentRange);
|
||||
|
||||
/// The identity information has been lost.
|
||||
///
|
||||
/// Seeing this error in user code indicates a bug in actix-identity.
|
||||
#[derive(Debug, Display, Error)]
|
||||
#[display(
|
||||
fmt = "The identity information in the current session has disappeared after having been \
|
||||
successfully validated. This is likely to be a bug."
|
||||
)]
|
||||
#[non_exhaustive]
|
||||
pub struct LostIdentityError;
|
||||
|
||||
/// There is no identity information attached to the current session.
|
||||
#[derive(Debug, Display, Error)]
|
||||
#[display(fmt = "There is no identity information attached to the current session")]
|
||||
#[non_exhaustive]
|
||||
pub struct MissingIdentityError;
|
||||
|
||||
/// Errors that can occur while retrieving an identity.
|
||||
#[derive(Debug, Display, Error, From)]
|
||||
#[non_exhaustive]
|
||||
pub enum GetIdentityError {
|
||||
/// The session has expired.
|
||||
#[display(fmt = "{_0}")]
|
||||
SessionExpiryError(SessionExpiryError),
|
||||
|
||||
/// No identity is found in a session.
|
||||
#[display(fmt = "{_0}")]
|
||||
MissingIdentityError(MissingIdentityError),
|
||||
|
||||
/// Failed to accessing the session store.
|
||||
#[display(fmt = "{_0}")]
|
||||
SessionGetError(SessionGetError),
|
||||
|
||||
/// Identity info was lost after being validated.
|
||||
///
|
||||
/// Seeing this error indicates a bug in actix-identity.
|
||||
#[display(fmt = "{_0}")]
|
||||
LostIdentityError(LostIdentityError),
|
||||
}
|
||||
|
||||
impl ResponseError for GetIdentityError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
match self {
|
||||
Self::LostIdentityError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
_ => StatusCode::UNAUTHORIZED,
|
||||
}
|
||||
}
|
||||
}
|
@ -6,9 +6,13 @@ use actix_web::{
|
||||
http::StatusCode,
|
||||
Error, FromRequest, HttpMessage, HttpRequest, HttpResponse,
|
||||
};
|
||||
use anyhow::{anyhow, Context};
|
||||
|
||||
use crate::config::LogoutBehaviour;
|
||||
use crate::{
|
||||
config::LogoutBehaviour,
|
||||
error::{
|
||||
GetIdentityError, LoginError, LostIdentityError, MissingIdentityError, SessionExpiryError,
|
||||
},
|
||||
};
|
||||
|
||||
/// A verified user identity. It can be used as a request extractor.
|
||||
///
|
||||
@ -95,13 +99,10 @@ impl IdentityInner {
|
||||
}
|
||||
|
||||
/// Retrieve the user id attached to the current session.
|
||||
fn get_identity(&self) -> Result<String, anyhow::Error> {
|
||||
fn get_identity(&self) -> Result<String, GetIdentityError> {
|
||||
self.session
|
||||
.get::<String>(ID_KEY)
|
||||
.context("Failed to deserialize the user identifier attached to the current session")?
|
||||
.ok_or_else(|| {
|
||||
anyhow!("There is no identity information attached to the current session")
|
||||
})
|
||||
.get::<String>(ID_KEY)?
|
||||
.ok_or_else(|| MissingIdentityError.into())
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,10 +127,11 @@ impl Identity {
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn id(&self) -> Result<String, anyhow::Error> {
|
||||
self.0.session.get(ID_KEY)?.ok_or_else(|| {
|
||||
anyhow!("Bug: the identity information attached to the current session has disappeared")
|
||||
})
|
||||
pub fn id(&self) -> Result<String, GetIdentityError> {
|
||||
self.0
|
||||
.session
|
||||
.get(ID_KEY)?
|
||||
.ok_or_else(|| LostIdentityError.into())
|
||||
}
|
||||
|
||||
/// Attach a valid user identity to the current session.
|
||||
@ -149,7 +151,7 @@ impl Identity {
|
||||
/// HttpResponse::Ok()
|
||||
/// }
|
||||
/// ```
|
||||
pub fn login(ext: &Extensions, id: String) -> Result<Self, anyhow::Error> {
|
||||
pub fn login(ext: &Extensions, id: String) -> Result<Self, LoginError> {
|
||||
let inner = IdentityInner::extract(ext);
|
||||
inner.session.insert(ID_KEY, id)?;
|
||||
let now = OffsetDateTime::now_utc().unix_timestamp();
|
||||
@ -200,31 +202,33 @@ impl Identity {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn extract(ext: &Extensions) -> Result<Self, anyhow::Error> {
|
||||
pub(crate) fn extract(ext: &Extensions) -> Result<Self, GetIdentityError> {
|
||||
let inner = IdentityInner::extract(ext);
|
||||
inner.get_identity()?;
|
||||
Ok(Self(inner))
|
||||
}
|
||||
|
||||
pub(crate) fn logged_at(&self) -> Result<Option<OffsetDateTime>, anyhow::Error> {
|
||||
self.0
|
||||
pub(crate) fn logged_at(&self) -> Result<Option<OffsetDateTime>, GetIdentityError> {
|
||||
Ok(self
|
||||
.0
|
||||
.session
|
||||
.get(LOGIN_UNIX_TIMESTAMP_KEY)?
|
||||
.map(OffsetDateTime::from_unix_timestamp)
|
||||
.transpose()
|
||||
.map_err(anyhow::Error::from)
|
||||
.map_err(SessionExpiryError)?)
|
||||
}
|
||||
|
||||
pub(crate) fn last_visited_at(&self) -> Result<Option<OffsetDateTime>, anyhow::Error> {
|
||||
self.0
|
||||
pub(crate) fn last_visited_at(&self) -> Result<Option<OffsetDateTime>, GetIdentityError> {
|
||||
Ok(self
|
||||
.0
|
||||
.session
|
||||
.get(LAST_VISIT_UNIX_TIMESTAMP_KEY)?
|
||||
.map(OffsetDateTime::from_unix_timestamp)
|
||||
.transpose()
|
||||
.map_err(anyhow::Error::from)
|
||||
.map_err(SessionExpiryError)?)
|
||||
}
|
||||
|
||||
pub(crate) fn set_last_visited_at(&self) -> Result<(), anyhow::Error> {
|
||||
pub(crate) fn set_last_visited_at(&self) -> Result<(), LoginError> {
|
||||
let now = OffsetDateTime::now_utc().unix_timestamp();
|
||||
self.0.session.insert(LAST_VISIT_UNIX_TIMESTAMP_KEY, now)?;
|
||||
Ok(())
|
||||
|
@ -1,27 +1,27 @@
|
||||
use actix_web::{dev::ServiceRequest, guard::GuardContext, HttpMessage, HttpRequest};
|
||||
|
||||
use crate::Identity;
|
||||
use crate::{error::GetIdentityError, Identity};
|
||||
|
||||
/// Helper trait to retrieve an [`Identity`] instance from various `actix-web`'s types.
|
||||
pub trait IdentityExt {
|
||||
/// Retrieve the identity attached to the current session, if available.
|
||||
fn get_identity(&self) -> Result<Identity, anyhow::Error>;
|
||||
fn get_identity(&self) -> Result<Identity, GetIdentityError>;
|
||||
}
|
||||
|
||||
impl IdentityExt for HttpRequest {
|
||||
fn get_identity(&self) -> Result<Identity, anyhow::Error> {
|
||||
fn get_identity(&self) -> Result<Identity, GetIdentityError> {
|
||||
Identity::extract(&self.extensions())
|
||||
}
|
||||
}
|
||||
|
||||
impl IdentityExt for ServiceRequest {
|
||||
fn get_identity(&self) -> Result<Identity, anyhow::Error> {
|
||||
fn get_identity(&self) -> Result<Identity, GetIdentityError> {
|
||||
Identity::extract(&self.extensions())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IdentityExt for GuardContext<'a> {
|
||||
fn get_identity(&self) -> Result<Identity, anyhow::Error> {
|
||||
fn get_identity(&self) -> Result<Identity, GetIdentityError> {
|
||||
Identity::extract(&self.req_data())
|
||||
}
|
||||
}
|
||||
|
@ -91,6 +91,7 @@
|
||||
#![warn(future_incompatible)]
|
||||
|
||||
pub mod config;
|
||||
pub mod error;
|
||||
mod identity;
|
||||
mod identity_ext;
|
||||
mod middleware;
|
||||
|
@ -32,7 +32,8 @@ impl TestApp {
|
||||
.listen(listener)
|
||||
.unwrap()
|
||||
.run();
|
||||
let _ = actix_web::rt::spawn(server);
|
||||
|
||||
actix_web::rt::spawn(server);
|
||||
|
||||
let client = reqwest::Client::builder()
|
||||
.cookie_store(true)
|
||||
|
@ -2,28 +2,30 @@
|
||||
|
||||
## Unreleased - 2022-xx-xx
|
||||
- Added optional scopes to the middleware enabling use of multiple Limiters by passing an `HashMap<Limiter>` to the Http server `app_data`
|
||||
- Update `redis` dependency to `0.22`.
|
||||
|
||||
## 0.4.0 - 2022-09-10
|
||||
|
||||
- Add `Builder::key_by` for setting a custom rate limit key function.
|
||||
- Implement `Default` for `RateLimiter`.
|
||||
- `RateLimiter` is marked `#[non_exhaustive]`; use `RateLimiter::default()` instead.
|
||||
- In the middleware errors from the count function are matched and respond with `INTERNAL_SERVER_ERROR` if it's an unexpected error, instead of the default `TOO_MANY_REQUESTS`.
|
||||
- Minimum supported Rust version (MSRV) is now 1.59 due to transitive `time` dependency.
|
||||
|
||||
|
||||
## 0.3.0 - 2022-07-11
|
||||
|
||||
- `Limiter::builder` now takes an `impl Into<String>`.
|
||||
- Removed lifetime from `Builder`.
|
||||
- Updated `actix-session` dependency to `0.7`.
|
||||
|
||||
|
||||
## 0.2.0 - 2022-03-22
|
||||
|
||||
- Update Actix Web dependency to v4 ecosystem.
|
||||
- Update Tokio dependencies to v1 ecosystem.
|
||||
- Rename `Limiter::{build => builder}()`.
|
||||
- Rename `Builder::{finish => build}()`.
|
||||
- Exceeding the rate limit now returns a 429 Too Many Requests response.
|
||||
|
||||
|
||||
## 0.1.4 - 2022-03-18
|
||||
|
||||
- Adopted into @actix org from <https://github.com/0xmad/actix-limitation>.
|
||||
|
@ -11,6 +11,11 @@ categories = ["asynchronous", "web-programming"]
|
||||
repository = "https://github.com/actix/actix-extras.git"
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2018"
|
||||
rust-version = "1.60"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
all-features = true
|
||||
|
||||
[features]
|
||||
default = ["session"]
|
||||
@ -21,9 +26,9 @@ actix-utils = "3"
|
||||
actix-web = { version = "4", features = ["cookies"] }
|
||||
|
||||
chrono = "0.4"
|
||||
derive_more = "0.99.5"
|
||||
derive_more = "0.99.7"
|
||||
log = "0.4"
|
||||
redis = { version = "0.21", default-features = false, features = ["tokio-comp"] }
|
||||
redis = { version = "0.22", default-features = false, features = ["tokio-comp"] }
|
||||
time = "0.3"
|
||||
|
||||
# session
|
||||
|
@ -21,7 +21,7 @@ async fn test_limiter_count() -> Result<(), Error> {
|
||||
|
||||
for i in 0..20 {
|
||||
let status = limiter.count(id.to_string()).await?;
|
||||
println!("status: {:?}", status);
|
||||
println!("status: {status:?}");
|
||||
assert_eq!(20 - status.remaining(), i + 1);
|
||||
}
|
||||
|
||||
|
@ -1,39 +1,40 @@
|
||||
# Changes
|
||||
|
||||
## Unreleased - 2022-xx-xx
|
||||
- Minimum supported Rust version (MSRV) is now 1.59 due to transitive `time` dependency.
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.60.
|
||||
|
||||
## 0.9.0 - 2022-08-24
|
||||
|
||||
- Added `application/x-protobuf` as an acceptable header.
|
||||
- Updated `prost` dependency to `0.11`.
|
||||
|
||||
|
||||
## 0.8.0 - 2022-06-25
|
||||
|
||||
- Update `prost` dependency to `0.10`.
|
||||
- Minimum supported Rust version (MSRV) is now 1.57 due to transitive `time` dependency.
|
||||
|
||||
|
||||
## 0.7.0 - 2022-03-01
|
||||
|
||||
- Update `actix-web` dependency to `4`.
|
||||
|
||||
|
||||
## 0.7.0-beta.5 - 2022-02-03
|
||||
|
||||
- Update `prost` dependency to `0.9`.
|
||||
- Update `actix-web` dependency to `4.0.0-rc.1`.
|
||||
|
||||
|
||||
## 0.7.0-beta.4 - 2021-12-29
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.54.
|
||||
|
||||
|
||||
## 0.7.0-beta.3 - 2021-12-12
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0.beta-14`. [#209]
|
||||
|
||||
[#209]: https://github.com/actix/actix-extras/pull/209
|
||||
|
||||
|
||||
## 0.7.0-beta.2 - 2021-10-21
|
||||
|
||||
- Bump `prost` version to 0.8. [#197]
|
||||
- Update `actix-web` dependency to v4.0.0-beta.10. [#203]
|
||||
- Minimum supported Rust version (MSRV) is now 1.52.
|
||||
@ -41,52 +42,52 @@
|
||||
[#197]: https://github.com/actix/actix-extras/pull/197
|
||||
[#203]: https://github.com/actix/actix-extras/pull/203
|
||||
|
||||
|
||||
## 0.7.0-beta.1 - 2021-06-27
|
||||
|
||||
- Bump `prost` version to 0.7. [#144]
|
||||
- Update `actix-web` dependency to 4.0.0 beta.
|
||||
- Minimum supported Rust version (MSRV) is now 1.46.0.
|
||||
|
||||
[#144]: https://github.com/actix/actix-extras/pull/144
|
||||
|
||||
|
||||
## 0.6.0 - 2020-09-11
|
||||
|
||||
- Update `actix-web` dependency to 3.0.0.
|
||||
- Minimum supported Rust version (MSRV) is now 1.42.0 to use `matches!` macro.
|
||||
|
||||
|
||||
## 0.6.0-alpha.1 - 2020-07-06
|
||||
|
||||
- Update `actix-web` to 3.0.0-alpha.3
|
||||
- Minimum supported Rust version(MSRV) is now 1.40.0.
|
||||
- Minimize `futures` dependency
|
||||
|
||||
|
||||
## 0.5.1 - 2019-02-17
|
||||
|
||||
- Move repository to actix-extras
|
||||
|
||||
|
||||
## 0.5.0 - 2019-01-24
|
||||
|
||||
- Migrate to actix-web 2.0.0 and std::future
|
||||
- Update prost to 0.6
|
||||
- Update bytes to 0.5
|
||||
|
||||
|
||||
## 0.4.1 - 2019-10-03
|
||||
|
||||
- Upgrade prost and prost-derive to 0.5.0
|
||||
|
||||
|
||||
## 0.4.0 - 2019-05-18
|
||||
|
||||
- Upgrade to actix-web 1.0.0-rc
|
||||
- Removed `protobuf` method for `HttpRequest` (use `ProtoBuf` extractor instead)
|
||||
|
||||
|
||||
## 0.3.0 - 2019-03-07
|
||||
|
||||
- Upgrade to actix-web 0.7.18
|
||||
|
||||
|
||||
## 0.2.0 - 2018-04-10
|
||||
|
||||
- Provide protobuf extractor
|
||||
|
||||
|
||||
## 0.1.0 - 2018-03-21
|
||||
|
||||
- First release
|
||||
|
@ -1,7 +1,6 @@
|
||||
[package]
|
||||
name = "actix-protobuf"
|
||||
version = "0.9.0"
|
||||
edition = "2018"
|
||||
authors = [
|
||||
"kingxsp <jin.hb.zh@outlook.com>",
|
||||
"Yuki Okushi <huyuumi.dev@gmail.com>",
|
||||
@ -11,17 +10,19 @@ keywords = ["actix", "web", "protobuf", "protocol", "rpc"]
|
||||
homepage = "https://actix.rs"
|
||||
repository = "https://github.com/actix/actix-extras.git"
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2018"
|
||||
rust-version = "1.60"
|
||||
|
||||
[lib]
|
||||
name = "actix_protobuf"
|
||||
path = "src/lib.rs"
|
||||
[package.metadata.docs.rs]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
all-features = true
|
||||
|
||||
[dependencies]
|
||||
actix-web = { version = "4", default_features = false }
|
||||
derive_more = "0.99.5"
|
||||
actix-web = { version = "4", default-features = false }
|
||||
derive_more = "0.99.7"
|
||||
futures-util = { version = "0.3.7", default-features = false }
|
||||
prost = { version = "0.11", default_features = false }
|
||||
prost = { version = "0.11", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-web = { version = "4", default_features = false, features = ["macros"] }
|
||||
prost = { version = "0.11", default_features = false, features = ["prost-derive"] }
|
||||
actix-web = { version = "4", default-features = false, features = ["macros"] }
|
||||
prost = { version = "0.11", default-features = false, features = ["prost-derive"] }
|
||||
|
@ -39,15 +39,15 @@ pub enum ProtoBufPayloadError {
|
||||
ContentType,
|
||||
|
||||
/// Serialize error
|
||||
#[display(fmt = "ProtoBuf serialize error: {}", _0)]
|
||||
#[display(fmt = "ProtoBuf serialize error: {_0}")]
|
||||
Serialize(ProtoBufEncodeError),
|
||||
|
||||
/// Deserialize error
|
||||
#[display(fmt = "ProtoBuf deserialize error: {}", _0)]
|
||||
#[display(fmt = "ProtoBuf deserialize error: {_0}")]
|
||||
Deserialize(ProtoBufDecodeError),
|
||||
|
||||
/// Payload error
|
||||
#[display(fmt = "Error that occur during reading payload: {}", _0)]
|
||||
#[display(fmt = "Error that occur during reading payload: {_0}")]
|
||||
Payload(PayloadError),
|
||||
}
|
||||
|
||||
|
@ -1,83 +1,87 @@
|
||||
# Changes
|
||||
|
||||
## Unreleased - 2022-xx-xx
|
||||
- Minimum supported Rust version (MSRV) is now 1.59 due to transitive `time` dependency.
|
||||
|
||||
- Update `redis-async` dependency to `0.14`.
|
||||
- Minimum supported Rust version (MSRV) is now 1.60.
|
||||
|
||||
## 0.12.0 - 2022-07-09
|
||||
|
||||
- Update `actix` dependency to `0.13`.
|
||||
- Update `redis-async` dependency to `0.13`.
|
||||
- Update `tokio-util` dependency to `0.7`.
|
||||
- Minimum supported Rust version (MSRV) is now 1.57 due to transitive `time` dependency.
|
||||
|
||||
|
||||
## 0.11.0 - 2022-03-15
|
||||
|
||||
### Removed
|
||||
|
||||
- `RedisSession` has been removed. Check out `RedisActorSessionStore` in `actix-session` for a session store backed by Redis using `actix-redis`. [#212]
|
||||
|
||||
### Changed
|
||||
|
||||
- Update `redis-async` dependency to `0.12`. [#212]
|
||||
|
||||
[#212]: https://github.com/actix/actix-extras/pull/212
|
||||
|
||||
|
||||
## 0.10.0 - 2022-03-01
|
||||
|
||||
- Update `actix-web` dependency to `4`.
|
||||
|
||||
|
||||
## 0.10.0-beta.6 - 2022-02-07
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0-rc.1`.
|
||||
|
||||
|
||||
## 0.10.0-beta.5 - 2021-12-29
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0.beta-18`. [#218]
|
||||
- Minimum supported Rust version (MSRV) is now 1.54.
|
||||
|
||||
[#218]: https://github.com/actix/actix-extras/pull/218
|
||||
|
||||
|
||||
## 0.10.0-beta.4 - 2021-12-12
|
||||
|
||||
- A session will be created in Redis if and only if there is some data inside the session state. This reduces the performance impact of `RedisSession` on routes that do not leverage sessions. [#207]
|
||||
- Update `actix-web` dependency to `4.0.0.beta-14`. [#209]
|
||||
|
||||
[#207]: https://github.com/actix/actix-extras/pull/207
|
||||
[#209]: https://github.com/actix/actix-extras/pull/209
|
||||
|
||||
|
||||
## 0.10.0-beta.3 - 2021-10-21
|
||||
|
||||
- Update `actix-web` dependency to v4.0.0-beta.10. [#203]
|
||||
- Minimum supported Rust version (MSRV) is now 1.52.
|
||||
|
||||
[#203]: https://github.com/actix/actix-extras/pull/203
|
||||
|
||||
|
||||
## 0.10.0-beta.2 - 2021-06-27
|
||||
|
||||
- No notable changes.
|
||||
|
||||
|
||||
## 0.10.0-beta.1 - 2021-04-02
|
||||
|
||||
- Update `actix-web` dependency to 4.0.0 beta.
|
||||
- Minimum supported Rust version (MSRV) is now 1.46.0.
|
||||
|
||||
|
||||
## 0.9.2 - 2021-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.
|
||||
|
||||
|
||||
## 0.9.0 - 2020-09-11
|
||||
|
||||
- Update `actix-web` dependency to 3.0.0.
|
||||
- Minimize `futures` dependency.
|
||||
|
||||
|
||||
## 0.9.0-alpha.2 - 2020-05-17
|
||||
|
||||
- Add `cookie_http_only` functionality to RedisSession builder, setting this
|
||||
to false allows JavaScript to access cookies. Defaults to true.
|
||||
- Change type of parameter of ttl method to u32.
|
||||
@ -85,69 +89,69 @@
|
||||
- Update `tokio-util` to 0.3
|
||||
- Minimum supported Rust version(MSRV) is now 1.40.0.
|
||||
|
||||
|
||||
## 0.9.0-alpha.1 - 2020-03-28
|
||||
|
||||
- Update `actix` to 0.10.0-alpha.2
|
||||
- Update `actix-session` to 0.4.0-alpha.1
|
||||
- Update `actix-web` to 3.0.0-alpha.1
|
||||
- Update `time` to 0.2.9
|
||||
|
||||
|
||||
## 0.8.1 - 2020-02-18
|
||||
|
||||
- Move `env_logger` dependency to dev-dependencies and update to 0.7
|
||||
- Update `actix_web` to 2.0.0 from 2.0.0-rc
|
||||
- Move repository to actix-extras
|
||||
|
||||
|
||||
## 0.8.0 - 2019-12-20
|
||||
|
||||
- Release
|
||||
|
||||
|
||||
## 0.8.0-alpha.1 - 2019-12-16
|
||||
|
||||
- Migrate to actix 0.9
|
||||
|
||||
|
||||
## 0.7.0 - 2019-09-25
|
||||
|
||||
- added cache_keygen functionality to RedisSession builder, enabling support for
|
||||
customizable cache key creation
|
||||
|
||||
|
||||
## 0.6.1 - 2019-07-19
|
||||
|
||||
- remove ClonableService usage
|
||||
- added comprehensive tests for session workflow
|
||||
|
||||
|
||||
## 0.6.0 - 2019-07-08
|
||||
|
||||
- actix-web 1.0.0 compatibility
|
||||
- Upgraded logic that evaluates session state, including new SessionStatus field,
|
||||
and introduced ``session.renew()`` and ``session.purge()`` functionality.
|
||||
Use ``renew()`` to cycle the session key at successful login. ``renew()`` keeps a
|
||||
and introduced `session.renew()` and `session.purge()` functionality.
|
||||
Use `renew()` to cycle the session key at successful login. `renew()` keeps a
|
||||
session's state while replacing the old cookie and session key with new ones.
|
||||
Use ``purge()`` at logout to invalidate the session cookie and remove the
|
||||
Use `purge()` at logout to invalidate the session cookie and remove the
|
||||
session's redis cache entry.
|
||||
|
||||
|
||||
## 0.5.1 - 2018-08-02
|
||||
|
||||
- Use cookie 0.11
|
||||
|
||||
|
||||
## 0.5.0 - 2018-07-21
|
||||
|
||||
- Session cookie configuration
|
||||
- Actix/Actix-web 0.7 compatibility
|
||||
|
||||
|
||||
## 0.4.0 - 2018-05-08
|
||||
|
||||
- Actix web 0.6 compatibility
|
||||
|
||||
|
||||
## 0.3.0 - 2018-04-10
|
||||
|
||||
- Actix web 0.5 compatibility
|
||||
|
||||
|
||||
## 0.2.0 - 2018-02-28
|
||||
|
||||
- Use resolver actor from actix
|
||||
- Use actix web 0.5
|
||||
|
||||
|
||||
## 0.1.0 - 2018-01-23
|
||||
|
||||
- First release
|
||||
|
@ -9,10 +9,11 @@ homepage = "https://actix.rs"
|
||||
repository = "https://github.com/actix/actix-extras.git"
|
||||
categories = ["network-programming", "asynchronous"]
|
||||
edition = "2018"
|
||||
rust-version = "1.60"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
all-features = true
|
||||
|
||||
[lib]
|
||||
name = "actix_redis"
|
||||
@ -32,16 +33,16 @@ actix-tls = { version = "3", default-features = false, features = ["connect"] }
|
||||
|
||||
log = "0.4.6"
|
||||
backoff = "0.4.0"
|
||||
derive_more = "0.99.5"
|
||||
derive_more = "0.99.7"
|
||||
futures-core = { version = "0.3.7", default-features = false }
|
||||
redis-async = "0.13"
|
||||
redis-async = "0.14"
|
||||
time = "0.3"
|
||||
tokio = { version = "1.13.1", features = ["sync"] }
|
||||
tokio = { version = "1.18.4", features = ["sync"] }
|
||||
tokio-util = "0.7"
|
||||
actix-web = { version = "4", default_features = false, optional = true }
|
||||
actix-web = { version = "4", default-features = false, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-test = "0.1.0-beta.12"
|
||||
actix-web = { version = "4", default_features = false, features = ["macros"] }
|
||||
env_logger = "0.9"
|
||||
actix-web = { version = "4", default-features = false, features = ["macros"] }
|
||||
env_logger = "0.10"
|
||||
serde = { version = "1.0.101", features = ["derive"] }
|
||||
|
@ -13,7 +13,7 @@ pub use self::redis::{Command, RedisActor};
|
||||
/// General purpose `actix-redis` error.
|
||||
#[derive(Debug, Display, Error, From)]
|
||||
pub enum Error {
|
||||
#[display(fmt = "Redis error: {}", _0)]
|
||||
#[display(fmt = "Redis error: {_0}")]
|
||||
Redis(redis_async::error::Error),
|
||||
|
||||
/// Receiving message during reconnecting.
|
||||
|
@ -31,7 +31,7 @@ async fn test_redis() {
|
||||
let res = addr.send(Command(resp_array!["GET", "test"])).await;
|
||||
match res {
|
||||
Ok(Ok(resp)) => {
|
||||
println!("RESP: {:?}", resp);
|
||||
println!("RESP: {resp:?}");
|
||||
assert_eq!(resp, RespValue::BulkString((&b"value"[..]).into()));
|
||||
}
|
||||
_ => panic!("Should not happen {:?}", res),
|
||||
|
@ -1,24 +1,26 @@
|
||||
# Changes
|
||||
|
||||
## Unreleased - 2021-xx-xx
|
||||
- Set secure attribute when adding a session removal cookie. [#300]
|
||||
|
||||
[#300]: https://github.com/actix/actix-extras/pull/300
|
||||
- Set secure attribute when adding a session removal cookie.
|
||||
- Update `redis` dependency to `0.22`.
|
||||
- Minimum supported Rust version (MSRV) is now 1.60.
|
||||
|
||||
## 0.7.2 - 2022-09-11
|
||||
|
||||
- Set SameSite attribute when adding a session removal cookie. [#284]
|
||||
- Minimum supported Rust version (MSRV) is now 1.59 due to transitive `time` dependency.
|
||||
|
||||
[#284]: https://github.com/actix/actix-extras/pull/284
|
||||
|
||||
|
||||
## 0.7.1 - 2022-07-24
|
||||
|
||||
- Fix interaction between session state changes and renewal. [#265]
|
||||
|
||||
[#265]: https://github.com/actix/actix-extras/pull/265
|
||||
|
||||
|
||||
## 0.7.0 - 2022-07-09
|
||||
|
||||
- Added `TtlExtensionPolicy` enum to support different strategies for extending the TTL attached to the session state. `TtlExtensionPolicy::OnEveryRequest` now allows for long-lived sessions that do not expire if the user remains active. [#233]
|
||||
- `SessionLength` is now called `SessionLifecycle`. [#233]
|
||||
- `SessionLength::Predetermined` is now called `SessionLifecycle::PersistentSession`. [#233]
|
||||
@ -34,8 +36,8 @@
|
||||
|
||||
[#233]: https://github.com/actix/actix-extras/pull/233
|
||||
|
||||
|
||||
## 0.6.2 - 2022-03-25
|
||||
|
||||
- Implement `SessionExt` for `GuardContext`. [#234]
|
||||
- `RedisSessionStore` will prevent connection timeouts from causing user-visible errors. [#235]
|
||||
- Do not leak internal implementation details to callers when errors occur. [#236]
|
||||
@ -44,13 +46,14 @@
|
||||
[#236]: https://github.com/actix/actix-extras/pull/236
|
||||
[#235]: https://github.com/actix/actix-extras/pull/235
|
||||
|
||||
|
||||
## 0.6.1 - 2022-03-21
|
||||
|
||||
- No significant changes since `0.6.0`.
|
||||
|
||||
|
||||
## 0.6.0 - 2022-03-15
|
||||
|
||||
### Added
|
||||
|
||||
- `SessionMiddleware`, a middleware to provide support for saving/updating/deleting session state against a pluggable storage backend (see `SessionStore` trait). [#212]
|
||||
- `CookieSessionStore`, a cookie-based backend to store session state. [#212]
|
||||
- `RedisActorSessionStore`, a Redis-based backend to store session state powered by `actix-redis`. [#212]
|
||||
@ -59,37 +62,39 @@
|
||||
- Implement `SessionExt` for `ServiceResponse`. [#212]
|
||||
|
||||
### Changed
|
||||
|
||||
- Rename `UserSession` to `SessionExt`. [#212]
|
||||
|
||||
### Removed
|
||||
|
||||
- `CookieSession`; replaced with `CookieSessionStore`, a storage backend for `SessionMiddleware`. [#212]
|
||||
- `Session::set_session`; use `Session::insert` to modify the session state. [#212]
|
||||
|
||||
[#212]: https://github.com/actix/actix-extras/pull/212
|
||||
|
||||
|
||||
## 0.5.0 - 2022-03-01
|
||||
|
||||
- Update `actix-web` dependency to `4`.
|
||||
|
||||
|
||||
## 0.5.0-beta.8 - 2022-02-07
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0-rc.1`.
|
||||
|
||||
|
||||
## 0.5.0-beta.7 - 2021-12-29
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0.beta-18`. [#218]
|
||||
- Minimum supported Rust version (MSRV) is now 1.54.
|
||||
|
||||
[#218]: https://github.com/actix/actix-extras/pull/218
|
||||
|
||||
|
||||
## 0.5.0-beta.6 - 2021-12-18
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0.beta-15`. [#216]
|
||||
|
||||
[#216]: https://github.com/actix/actix-extras/pull/216
|
||||
|
||||
|
||||
## 0.5.0-beta.5 - 2021-12-12
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0.beta-14`. [#209]
|
||||
- Remove `UserSession` implementation for `RequestHead`. [#209]
|
||||
- A session will be created in the storage backend if and only if there is some data inside the session state. This reduces the performance impact of `SessionMiddleware` on routes that do not leverage sessions. [#207]
|
||||
@ -97,12 +102,12 @@
|
||||
[#207]: https://github.com/actix/actix-extras/pull/207
|
||||
[#209]: https://github.com/actix/actix-extras/pull/209
|
||||
|
||||
|
||||
## 0.5.0-beta.4 - 2021-11-22
|
||||
|
||||
- No significant changes since `0.5.0-beta.3`.
|
||||
|
||||
|
||||
## 0.5.0-beta.3 - 2021-10-21
|
||||
|
||||
- Impl `Clone` for `CookieSession`. [#201]
|
||||
- Update `actix-web` dependency to v4.0.0-beta.10. [#203]
|
||||
- Minimum supported Rust version (MSRV) is now 1.52.
|
||||
@ -110,12 +115,12 @@
|
||||
[#201]: https://github.com/actix/actix-extras/pull/201
|
||||
[#203]: https://github.com/actix/actix-extras/pull/203
|
||||
|
||||
|
||||
## 0.5.0-beta.2 - 2021-06-27
|
||||
|
||||
- No notable changes.
|
||||
|
||||
|
||||
## 0.5.0-beta.1 - 2021-04-02
|
||||
|
||||
- Add `Session::entries`. [#170]
|
||||
- Rename `Session::{set => insert}` to match standard hash map naming. [#170]
|
||||
- Return values from `Session::remove`. [#170]
|
||||
@ -127,21 +132,21 @@
|
||||
|
||||
[#170]: https://github.com/actix/actix-extras/pull/170
|
||||
|
||||
|
||||
## 0.4.1 - 2021-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
|
||||
|
||||
- Update `actix-web` dependency to 3.0.0.
|
||||
- Minimum supported Rust version (MSRV) is now 1.42.0.
|
||||
|
||||
|
||||
## 0.4.0-alpha.1 - 2020-03-14
|
||||
|
||||
- Update the `time` dependency to 0.2.7
|
||||
- Update the `actix-web` dependency to 3.0.0-alpha.1
|
||||
- Long lasting auto-prolonged session [#1292]
|
||||
@ -149,65 +154,65 @@
|
||||
|
||||
[#1292]: https://github.com/actix/actix-web/pull/1292
|
||||
|
||||
|
||||
## 0.3.0 - 2019-12-20
|
||||
|
||||
- Release
|
||||
|
||||
|
||||
## 0.3.0-alpha.4 - 2019-12-xx
|
||||
|
||||
- Allow access to sessions also from not mutable references to the request
|
||||
|
||||
|
||||
## 0.3.0-alpha.3 - 2019-12-xx
|
||||
|
||||
- Add access to the session from RequestHead for use of session from guard methods
|
||||
- Migrate to `std::future`
|
||||
- Migrate to `actix-web` 2.0
|
||||
|
||||
|
||||
## 0.2.0 - 2019-07-08
|
||||
- Enhanced ``actix-session`` to facilitate state changes. Use ``Session.renew()``
|
||||
|
||||
- Enhanced `actix-session` to facilitate state changes. Use `Session.renew()`
|
||||
at successful login to cycle a session (new key/cookie but keeps state).
|
||||
Use ``Session.purge()`` at logout to invalid a session cookie (and remove
|
||||
Use `Session.purge()` at logout to invalid a session cookie (and remove
|
||||
from redis cache, if applicable).
|
||||
|
||||
|
||||
## 0.1.1 - 2019-06-03
|
||||
|
||||
- Fix optional cookie session support
|
||||
|
||||
|
||||
## 0.1.0 - 2019-05-18
|
||||
|
||||
- Use actix-web 1.0.0-rc
|
||||
|
||||
|
||||
## 0.1.0-beta.4 - 2019-05-12
|
||||
|
||||
- Use actix-web 1.0.0-beta.4
|
||||
|
||||
|
||||
## 0.1.0-beta.2 - 2019-04-28
|
||||
|
||||
- Add helper trait `UserSession` which allows to get session for ServiceRequest and HttpRequest
|
||||
|
||||
|
||||
## 0.1.0-beta.1 - 2019-04-20
|
||||
|
||||
- Update actix-web to beta.1
|
||||
- `CookieSession::max_age()` accepts value in seconds
|
||||
|
||||
|
||||
## 0.1.0-alpha.6 - 2019-04-14
|
||||
|
||||
- Update actix-web alpha.6
|
||||
|
||||
|
||||
## 0.1.0-alpha.4 - 2019-04-08
|
||||
- Update actix-web
|
||||
|
||||
- Update actix-web
|
||||
|
||||
## 0.1.0-alpha.3 - 2019-04-02
|
||||
|
||||
- Update actix-web
|
||||
|
||||
|
||||
## 0.1.0-alpha.2 - 2019-03-29
|
||||
|
||||
- Update actix-web
|
||||
- Use new feature name for secure cookies
|
||||
|
||||
|
||||
## 0.1.0-alpha.1 - 2019-03-28
|
||||
|
||||
- Initial impl
|
||||
|
@ -11,14 +11,11 @@ homepage = "https://actix.rs"
|
||||
repository = "https://github.com/actix/actix-extras.git"
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2018"
|
||||
rust-version = "1.60"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[lib]
|
||||
name = "actix_session"
|
||||
path = "src/lib.rs"
|
||||
all-features = true
|
||||
|
||||
[features]
|
||||
default = []
|
||||
@ -30,11 +27,11 @@ redis-rs-tls-session = ["redis-rs-session", "redis/tokio-native-tls-comp"]
|
||||
[dependencies]
|
||||
actix-service = "2"
|
||||
actix-utils = "3"
|
||||
actix-web = { version = "4", default_features = false, features = ["cookies", "secure-cookies"] }
|
||||
actix-web = { version = "4", default-features = false, features = ["cookies", "secure-cookies"] }
|
||||
|
||||
anyhow = "1"
|
||||
async-trait = "0.1"
|
||||
derive_more = "0.99.5"
|
||||
derive_more = "0.99.7"
|
||||
rand = { version = "0.8", optional = true }
|
||||
serde = { version = "1" }
|
||||
serde_json = { version = "1" }
|
||||
@ -46,13 +43,13 @@ actix-redis = { version = "0.12", optional = true }
|
||||
futures-core = { version = "0.3.7", default-features = false, optional = true }
|
||||
|
||||
# redis-rs-session
|
||||
redis = { version = "0.21", default-features = false, features = ["aio", "tokio-comp", "connection-manager"], optional = true }
|
||||
redis = { version = "0.22", default-features = false, features = ["tokio-comp", "connection-manager"], optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-session = { path = ".", features = ["cookie-session", "redis-actor-session", "redis-rs-session"] }
|
||||
actix-test = "0.1.0-beta.10"
|
||||
actix-web = { version = "4", default_features = false, features = ["cookies", "secure-cookies", "macros"] }
|
||||
env_logger = "0.9"
|
||||
actix-web = { version = "4", default-features = false, features = ["cookies", "secure-cookies", "macros"] }
|
||||
env_logger = "0.10"
|
||||
log = "0.4"
|
||||
|
||||
[[example]]
|
||||
|
@ -21,7 +21,7 @@ struct User {
|
||||
|
||||
impl User {
|
||||
fn authenticate(credentials: Credentials) -> Result<Self, HttpResponse> {
|
||||
// TODO: figure out why I keep getting hacked
|
||||
// to do: figure out why I keep getting hacked /s
|
||||
if &credentials.password != "hunter2" {
|
||||
return Err(HttpResponse::Unauthorized().json("Unauthorized"));
|
||||
}
|
||||
|
@ -3,11 +3,11 @@ use actix_web::{cookie::Key, middleware, web, App, Error, HttpRequest, HttpServe
|
||||
|
||||
/// simple handler
|
||||
async fn index(req: HttpRequest, session: Session) -> Result<impl Responder, Error> {
|
||||
println!("{:?}", req);
|
||||
println!("{req:?}");
|
||||
|
||||
// session
|
||||
if let Some(count) = session.get::<i32>("counter")? {
|
||||
println!("SESSION value: {}", count);
|
||||
println!("SESSION value: {count}");
|
||||
session.insert("counter", count + 1)?;
|
||||
} else {
|
||||
session.insert("counter", 1)?;
|
||||
|
@ -138,7 +138,7 @@
|
||||
#![warn(future_incompatible, missing_docs)]
|
||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
|
||||
pub mod config;
|
||||
mod middleware;
|
||||
@ -179,7 +179,7 @@ pub mod test_helpers {
|
||||
CookieContentSecurity::Signed,
|
||||
CookieContentSecurity::Private,
|
||||
] {
|
||||
println!("Using {:?} as cookie content security policy.", policy);
|
||||
println!("Using {policy:?} as cookie content security policy.");
|
||||
acceptance_tests::basic_workflow(store_builder.clone(), *policy).await;
|
||||
acceptance_tests::expiration_is_refreshed_on_changes(store_builder.clone(), *policy)
|
||||
.await;
|
||||
@ -243,7 +243,7 @@ pub mod test_helpers {
|
||||
}))
|
||||
.service(web::resource("/test/").to(|ses: Session| async move {
|
||||
let val: usize = ses.get("counter").unwrap().unwrap();
|
||||
format!("counter: {}", val)
|
||||
format!("counter: {val}")
|
||||
})),
|
||||
)
|
||||
.await;
|
||||
@ -710,9 +710,9 @@ pub mod test_helpers {
|
||||
async fn logout(session: Session) -> Result<HttpResponse> {
|
||||
let id: Option<String> = session.get("user_id")?;
|
||||
|
||||
let body = if let Some(x) = id {
|
||||
let body = if let Some(id) = id {
|
||||
session.purge();
|
||||
format!("Logged out: {}", x)
|
||||
format!("Logged out: {id}")
|
||||
} else {
|
||||
"Could not log out anonymous user".to_owned()
|
||||
};
|
||||
@ -726,10 +726,7 @@ pub mod test_helpers {
|
||||
|
||||
impl ServiceResponseExt for ServiceResponse {
|
||||
fn get_cookie(&self, cookie_name: &str) -> Option<actix_web::cookie::Cookie<'_>> {
|
||||
self.response()
|
||||
.cookies()
|
||||
.into_iter()
|
||||
.find(|c| c.name() == cookie_name)
|
||||
self.response().cookies().find(|c| c.name() == cookie_name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ impl FromRequest for Session {
|
||||
|
||||
/// Error returned by [`Session::get`].
|
||||
#[derive(Debug, Display, From)]
|
||||
#[display(fmt = "{}", _0)]
|
||||
#[display(fmt = "{_0}")]
|
||||
pub struct SessionGetError(anyhow::Error);
|
||||
|
||||
impl StdError for SessionGetError {
|
||||
@ -308,7 +308,7 @@ impl ResponseError for SessionGetError {
|
||||
|
||||
/// Error returned by [`Session::insert`].
|
||||
#[derive(Debug, Display, From)]
|
||||
#[display(fmt = "{}", _0)]
|
||||
#[display(fmt = "{_0}")]
|
||||
pub struct SessionInsertError(anyhow::Error);
|
||||
|
||||
impl StdError for SessionInsertError {
|
||||
|
@ -47,7 +47,6 @@ use crate::storage::{
|
||||
/// storage backend.
|
||||
///
|
||||
/// [`CookieContentSecurity::Private`]: crate::config::CookieContentSecurity::Private
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "cookie-session")))]
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
pub struct CookieSessionStore;
|
||||
|
@ -53,7 +53,6 @@ use crate::storage::{
|
||||
/// Redis. Use [`RedisSessionStore`] if you need TLS support.
|
||||
///
|
||||
/// [`RedisSessionStore`]: crate::storage::RedisSessionStore
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "redis-actor-session")))]
|
||||
pub struct RedisActorSessionStore {
|
||||
configuration: CacheConfiguration,
|
||||
addr: Addr<RedisActor>,
|
||||
@ -93,7 +92,6 @@ impl Default for CacheConfiguration {
|
||||
|
||||
/// A fluent builder to construct a [`RedisActorSessionStore`] instance with custom configuration
|
||||
/// parameters.
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "redis-actor-session")))]
|
||||
#[must_use]
|
||||
pub struct RedisActorSessionStoreBuilder {
|
||||
connection_string: String,
|
||||
|
@ -60,7 +60,6 @@ use crate::storage::{
|
||||
/// `RedisSessionStore` leverages [`redis-rs`] as Redis client.
|
||||
///
|
||||
/// [`redis-rs`]: https://github.com/mitsuhiko/redis-rs
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "redis-rs-session")))]
|
||||
#[derive(Clone)]
|
||||
pub struct RedisSessionStore {
|
||||
configuration: CacheConfiguration,
|
||||
@ -105,7 +104,6 @@ impl RedisSessionStore {
|
||||
/// parameters.
|
||||
///
|
||||
/// [`RedisSessionStore`]: crate::storage::RedisSessionStore
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "redis-rs-session")))]
|
||||
#[must_use]
|
||||
pub struct RedisSessionStoreBuilder {
|
||||
connection_string: String,
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
- Rename `AtError => Error`.
|
||||
- Remove `AtResult` type alias.
|
||||
- Minimum supported Rust version (MSRV) is now 1.59 due to transitive `time` dependency.
|
||||
- Minimum supported Rust version (MSRV) is now 1.60.
|
||||
|
||||
## 0.6.0 - 2022-07-31
|
||||
|
||||
|
@ -5,9 +5,14 @@ authors = [
|
||||
"Joey Ezechiels <joey.ezechiels@gmail.com>",
|
||||
"Rob Ede <robjtede@icloud.com>",
|
||||
]
|
||||
edition = "2018"
|
||||
description = "Easily manage Actix Web's settings from a TOML file and environment variables"
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2018"
|
||||
rust-version = "1.60"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
all-features = true
|
||||
|
||||
[dependencies]
|
||||
actix-http = "3"
|
||||
@ -21,4 +26,4 @@ serde = { version = "1", features = ["derive"] }
|
||||
toml = "0.5"
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.9"
|
||||
env_logger = "0.10"
|
||||
|
@ -89,7 +89,7 @@ impl From<Error> for io::Error {
|
||||
fn from(err: Error) -> Self {
|
||||
match err {
|
||||
Error::EnvVarError(var_error) => {
|
||||
let msg = format!("Env var error: {}", var_error);
|
||||
let msg = format!("Env var error: {var_error}");
|
||||
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
||||
}
|
||||
|
||||
@ -105,32 +105,29 @@ impl From<Error> for io::Error {
|
||||
line,
|
||||
column,
|
||||
} => {
|
||||
let msg = format!(
|
||||
"Expected {}, got {} (@ {}:{}:{})",
|
||||
expected, got, file, line, column
|
||||
);
|
||||
let msg = format!("Expected {expected}, got {got} (@ {file}:{line}:{column})");
|
||||
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
||||
}
|
||||
|
||||
Error::IoError(io_error) => io_error.into(),
|
||||
|
||||
Error::ParseBoolError(parse_bool_error) => {
|
||||
let msg = format!("Failed to parse boolean: {}", parse_bool_error);
|
||||
let msg = format!("Failed to parse boolean: {parse_bool_error}");
|
||||
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
||||
}
|
||||
|
||||
Error::ParseIntError(parse_int_error) => {
|
||||
let msg = format!("Failed to parse integer: {}", parse_int_error);
|
||||
let msg = format!("Failed to parse integer: {parse_int_error}");
|
||||
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
||||
}
|
||||
|
||||
Error::ParseAddressError(string) => {
|
||||
let msg = format!("Failed to parse address: {}", string);
|
||||
let msg = format!("Failed to parse address: {string}");
|
||||
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
||||
}
|
||||
|
||||
Error::TomlError(toml_error) => {
|
||||
let msg = format!("TOML error: {}", toml_error);
|
||||
let msg = format!("TOML error: {toml_error}");
|
||||
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
||||
}
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ where
|
||||
todo!("[ApplySettings] TLS support has not been implemented yet.");
|
||||
} else {
|
||||
for Address { host, port } in &settings.actix.hosts {
|
||||
self = self.bind(format!("{}:{}", host, port))
|
||||
self = self.bind(format!("{host}:{port}"))
|
||||
.unwrap(/*TODO*/);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
# Changes
|
||||
|
||||
## Unreleased - 2022-xx-xx
|
||||
- Minimum supported Rust version (MSRV) is now 1.59 due to transitive `time` dependency.
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.60.
|
||||
|
||||
## 0.8.0 - 2022-07-21
|
||||
|
||||
- Removed `AuthExtractor` trait; implement `FromRequest` for your custom auth types. [#264]
|
||||
- `BasicAuth::user_id()` now returns `&str`. [#249]
|
||||
- `BasicAuth::password()` now returns `Option<&str>`. [#249]
|
||||
@ -15,75 +16,75 @@
|
||||
[#249]: https://github.com/actix/actix-extras/pull/249
|
||||
[#264]: https://github.com/actix/actix-extras/pull/264
|
||||
|
||||
|
||||
## 0.7.0 - 2022-07-19
|
||||
|
||||
- Auth validator functions now need to return `(Error, ServiceRequest)` in error cases. [#260]
|
||||
- Minimum supported Rust version (MSRV) is now 1.57 due to transitive `time` dependency.
|
||||
|
||||
[#260]: https://github.com/actix/actix-extras/pull/260
|
||||
|
||||
|
||||
## 0.6.0 - 2022-03-01
|
||||
|
||||
- Update `actix-web` dependency to `4`.
|
||||
|
||||
|
||||
## 0.6.0-beta.8 - 2022-02-07
|
||||
|
||||
- Relax body type bounds on middleware impl. [#223]
|
||||
- Update `actix-web` dependency to `4.0.0-rc.1`.
|
||||
|
||||
[#223]: https://github.com/actix/actix-extras/pull/223
|
||||
|
||||
|
||||
## 0.6.0-beta.7 - 2021-12-29
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.54.
|
||||
|
||||
|
||||
## 0.6.0-beta.6 - 2021-12-18
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0.beta-15`. [#216]
|
||||
|
||||
[#216]: https://github.com/actix/actix-extras/pull/216
|
||||
|
||||
|
||||
## 0.6.0-beta.5 - 2021-12-12
|
||||
|
||||
- Update `actix-web` dependency to `4.0.0.beta-14`. [#209]
|
||||
|
||||
[#209]: https://github.com/actix/actix-extras/pull/209
|
||||
|
||||
|
||||
## 0.6.0-beta.4 - 2021-11-22
|
||||
|
||||
- impl `AuthExtractor` trait for `Option<T: AuthExtractor>` and `Result<T: AuthExtractor, T::Error>`. [#205]
|
||||
|
||||
[#205]: https://github.com/actix/actix-extras/pull/205
|
||||
|
||||
|
||||
## 0.6.0-beta.3 - 2021-10-21
|
||||
|
||||
- Update `actix-web` dependency to v4.0.0-beta.10. [#203]
|
||||
- Minimum supported Rust version (MSRV) is now 1.52.
|
||||
|
||||
[#203]: https://github.com/actix/actix-extras/pull/203
|
||||
|
||||
|
||||
## 0.6.0-beta.2 - 2021-06-27
|
||||
|
||||
- No notable changes.
|
||||
|
||||
|
||||
## 0.6.0-beta.1 - 2021-04-02
|
||||
|
||||
- Update `actix-web` dependency to 4.0.0 beta.
|
||||
- Minimum supported Rust version (MSRV) is now 1.46.0.
|
||||
|
||||
|
||||
## 0.5.1 - 2021-03-21
|
||||
|
||||
- Correct error handling when extracting auth details from request. [#128]
|
||||
|
||||
[#128]: https://github.com/actix/actix-extras/pull/128
|
||||
|
||||
|
||||
## 0.5.0 - 2020-09-11
|
||||
|
||||
- Update `actix-web` dependency to 3.0.0.
|
||||
- Minimum supported Rust version (MSRV) is now 1.42.0.
|
||||
|
||||
|
||||
## 0.4.2 - 2020-07-08
|
||||
|
||||
- Update the `base64` dependency to 0.12
|
||||
- AuthenticationError's status code is preserved when converting to a ResponseError
|
||||
- Minimize `futures` dependency
|
||||
@ -91,46 +92,46 @@
|
||||
|
||||
[#69]: https://github.com/actix/actix-web-httpauth/pull/69
|
||||
|
||||
|
||||
## 0.4.1 - 2020-02-19
|
||||
|
||||
- Move repository to actix-extras
|
||||
|
||||
|
||||
## 0.4.0 - 2020-01-14
|
||||
|
||||
- Depends on `actix-web = "^2.0"`, `actix-service = "^1.0"`, and `futures = "^0.3"` version now ([#14])
|
||||
- Depends on `bytes = "^0.5"` and `base64 = "^0.11"` now
|
||||
|
||||
[#14]: https://github.com/actix/actix-web-httpauth/pull/14
|
||||
|
||||
|
||||
## 0.3.2 - 2019-07-19
|
||||
|
||||
- Middleware accepts any `Fn` as a validator function instead of `FnMut` [#11]
|
||||
|
||||
[#11]: https://github.com/actix/actix-web-httpauth/pull/11
|
||||
|
||||
|
||||
## 0.3.1 - 2019-06-09
|
||||
|
||||
- Multiple calls to the middleware would result in panic
|
||||
|
||||
|
||||
## 0.3.0 - 2019-06-05
|
||||
|
||||
- Crate edition was changed to `2018`, same as `actix-web`
|
||||
- Depends on `actix-web = "^1.0"` version now
|
||||
- `WWWAuthenticate` header struct was renamed into `WwwAuthenticate`
|
||||
- Challenges and extractor configs are now operating with `Cow<'static, str>` types instead of `String` types
|
||||
|
||||
|
||||
## 0.2.0 - 2019-04-26
|
||||
|
||||
- `actix-web` dependency is used without default features now [#6]
|
||||
- `base64` dependency version was bumped to `0.10`
|
||||
|
||||
[#6]: https://github.com/actix/actix-web-httpauth/pull/6
|
||||
|
||||
|
||||
## 0.1.0 - 2018-09-08
|
||||
|
||||
- Update to `actix-web = "0.7"` version
|
||||
|
||||
|
||||
## 0.0.4 - 2018-07-01
|
||||
|
||||
- Fix possible panic at `IntoHeaderValue` implementation for `headers::authorization::Basic`
|
||||
- Fix possible panic at `headers::www_authenticate::challenge::bearer::Bearer::to_bytes` call
|
||||
|
@ -12,16 +12,17 @@ repository = "https://github.com/actix/actix-extras.git"
|
||||
categories = ["web-programming::http-server"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2018"
|
||||
rust-version = "1.60"
|
||||
|
||||
[lib]
|
||||
name = "actix_web_httpauth"
|
||||
path = "src/lib.rs"
|
||||
[package.metadata.docs.rs]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
all-features = true
|
||||
|
||||
[dependencies]
|
||||
actix-utils = "3"
|
||||
actix-web = { version = "4.1", default_features = false }
|
||||
actix-web = { version = "4.1", default-features = false }
|
||||
|
||||
base64 = "0.13"
|
||||
base64 = "0.21"
|
||||
futures-core = "0.3.7"
|
||||
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
|
||||
log = "0.4"
|
||||
@ -30,4 +31,4 @@ pin-project-lite = "0.2.7"
|
||||
[dev-dependencies]
|
||||
actix-cors = "0.6"
|
||||
actix-service = "2"
|
||||
actix-web = { version = "4.1", default_features = false, features = ["macros"] }
|
||||
actix-web = { version = "4.1", default-features = false, features = ["macros"] }
|
||||
|
@ -6,7 +6,7 @@ async fn ok_validator(
|
||||
req: ServiceRequest,
|
||||
credentials: BearerAuth,
|
||||
) -> Result<ServiceRequest, (Error, ServiceRequest)> {
|
||||
eprintln!("{:?}", credentials);
|
||||
eprintln!("{credentials:?}");
|
||||
Ok(req)
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ impl fmt::Display for ParseError {
|
||||
match self {
|
||||
ParseError::Invalid => f.write_str("Invalid header value"),
|
||||
ParseError::MissingScheme => f.write_str("Missing authorization scheme"),
|
||||
ParseError::MissingField(field) => write!(f, "Missing header field ({})", field),
|
||||
ParseError::MissingField(field) => write!(f, "Missing header field ({field})"),
|
||||
ParseError::ToStrError(err) => fmt::Display::fmt(err, f),
|
||||
ParseError::Base64DecodeError(err) => fmt::Display::fmt(err, f),
|
||||
ParseError::Utf8Error(err) => fmt::Display::fmt(err, f),
|
||||
|
@ -4,6 +4,7 @@ use actix_web::{
|
||||
http::header::{HeaderValue, InvalidHeaderValue, TryIntoHeaderValue},
|
||||
web::{BufMut, BytesMut},
|
||||
};
|
||||
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||
|
||||
use crate::headers::authorization::{errors::ParseError, Scheme};
|
||||
|
||||
@ -58,7 +59,7 @@ impl Scheme for Basic {
|
||||
_ => return Err(ParseError::MissingScheme),
|
||||
}
|
||||
|
||||
let decoded = base64::decode(parts.next().ok_or(ParseError::Invalid)?)?;
|
||||
let decoded = BASE64_STANDARD.decode(parts.next().ok_or(ParseError::Invalid)?)?;
|
||||
let mut credentials = str::from_utf8(&decoded)?.splitn(2, ':');
|
||||
|
||||
let user_id = credentials
|
||||
@ -97,11 +98,13 @@ impl TryIntoHeaderValue for Basic {
|
||||
type Error = InvalidHeaderValue;
|
||||
|
||||
fn try_into_value(self) -> Result<HeaderValue, Self::Error> {
|
||||
let mut credentials = BytesMut::with_capacity(
|
||||
self.user_id.len()
|
||||
+ 1 // ':'
|
||||
+ self.password.as_ref().map_or(0, |pwd| pwd.len()),
|
||||
);
|
||||
let credential_length =
|
||||
self.user_id.len() + 1 + self.password.as_ref().map_or(0, |pwd| pwd.len());
|
||||
// The length of BASE64 encoded bytes is `4 * credential_length.div_ceil(3)`
|
||||
// TODO: Use credential_length.div_ceil(3) when `int_roundings` becomes stable
|
||||
// https://github.com/rust-lang/rust/issues/88581
|
||||
let mut value = String::with_capacity(6 + 4 * (credential_length + 2) / 3);
|
||||
let mut credentials = BytesMut::with_capacity(credential_length);
|
||||
|
||||
credentials.extend_from_slice(self.user_id.as_bytes());
|
||||
credentials.put_u8(b':');
|
||||
@ -109,14 +112,10 @@ impl TryIntoHeaderValue for Basic {
|
||||
credentials.extend_from_slice(password.as_bytes());
|
||||
}
|
||||
|
||||
// TODO: It would be nice not to allocate new `String` here but write
|
||||
// directly to `value`
|
||||
let encoded = base64::encode(&credentials);
|
||||
let mut value = BytesMut::with_capacity(6 + encoded.len());
|
||||
value.put(&b"Basic "[..]);
|
||||
value.put(encoded.as_bytes());
|
||||
value.push_str("Basic ");
|
||||
BASE64_STANDARD.encode_string(&credentials, &mut value);
|
||||
|
||||
HeaderValue::from_maybe_shared(value.freeze())
|
||||
HeaderValue::from_maybe_shared(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,14 +12,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn to_bytes() {
|
||||
let b = Bearer::build()
|
||||
let bearer = Bearer::build()
|
||||
.error(Error::InvalidToken)
|
||||
.error_description("Subject 8740827c-2e0a-447b-9716-d73042e4039d not found")
|
||||
.finish();
|
||||
|
||||
assert_eq!(
|
||||
"Bearer error=\"invalid_token\" error_description=\"Subject 8740827c-2e0a-447b-9716-d73042e4039d not found\"",
|
||||
format!("{}", b)
|
||||
format!("{bearer}")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
msrv = "1.59"
|
||||
msrv = "1.60"
|
||||
|
Loading…
x
Reference in New Issue
Block a user