1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 00:21:08 +01:00

move identity service separate crate

This commit is contained in:
Nikolay Kim 2019-06-12 15:52:48 +06:00
parent ee769832cf
commit ff724e239d
12 changed files with 92 additions and 32 deletions

View File

@ -1,6 +1,6 @@
# Changes
## [1.0.x] - 2019-xx-xx
## [1.0.1] - 2019-06-xx
### Add
@ -8,7 +8,9 @@
### Changes
### Fixed
* Disable default feature `secure-cookies`.
* Move identity middleware to `actix-identity` crate.
## [1.0.0] - 2019-06-05

View File

@ -34,6 +34,7 @@ members = [
"actix-files",
"actix-framed",
"actix-session",
"actix-identity",
"actix-multipart",
"actix-web-actors",
"actix-web-codegen",
@ -41,7 +42,7 @@ members = [
]
[features]
default = ["brotli", "flate2-zlib", "secure-cookies", "client", "fail"]
default = ["brotli", "flate2-zlib", "client", "fail"]
# http client
client = ["awc"]
@ -77,7 +78,7 @@ actix-http = "0.2.3"
actix-server = "0.5.1"
actix-server-config = "0.1.1"
actix-threadpool = "0.1.1"
awc = { version = "0.2.0", optional = true }
awc = { version = "0.2.1", optional = true }
bytes = "0.4"
derive_more = "0.14"

View File

@ -1,3 +1,20 @@
## 1.0.1
* Identity middleware has been moved to `actix-identity` crate
instead of
```rust
use actix_web::middleware::identity::{Identity, CookieIdentityPolicy, IdentityService};
```
use
```rust
use actix_identity::{Identity, CookieIdentityPolicy, IdentityService};
```
## 1.0
* Resource registration. 1.0 version uses generalized resource

View File

@ -0,0 +1,5 @@
# Changes
## [0.1.0] - 2019-06-xx
* Move identity middleware to separate crate

29
actix-identity/Cargo.toml Normal file
View File

@ -0,0 +1,29 @@
[package]
name = "actix-identity"
version = "0.1.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Identity service for actix web framework."
readme = "README.md"
keywords = ["http", "web", "framework", "async", "futures"]
homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-web.git"
documentation = "https://docs.rs/actix-identity/"
license = "MIT/Apache-2.0"
edition = "2018"
workspace = ".."
[lib]
name = "actix_identity"
path = "src/lib.rs"
[dependencies]
actix-web = { version = "1.0.0", default-features = false, features = ["secure-cookies"] }
actix-service = "0.4.0"
futures = "0.1.25"
serde = "1.0"
serde_json = "1.0"
time = "0.1.42"
[dev-dependencies]
actix-rt = "0.2.2"
actix-http = "0.2.3"

View File

@ -0,0 +1 @@
../LICENSE-APACHE

1
actix-identity/LICENSE-MIT Symbolic link
View File

@ -0,0 +1 @@
../LICENSE-MIT

9
actix-identity/README.md Normal file
View File

@ -0,0 +1,9 @@
# Identity service for actix web framework [![Build Status](https://travis-ci.org/actix/actix-web.svg?branch=master)](https://travis-ci.org/actix/actix-web) [![codecov](https://codecov.io/gh/actix/actix-web/branch/master/graph/badge.svg)](https://codecov.io/gh/actix/actix-web) [![crates.io](https://meritbadge.herokuapp.com/actix-identity)](https://crates.io/crates/actix-identity) [![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)
## Documentation & community resources
* [User Guide](https://actix.rs/docs/)
* [API Documentation](https://docs.rs/actix-identity/)
* [Chat on gitter](https://gitter.im/actix/actix)
* Cargo package: [actix-session](https://crates.io/crates/actix-identity)
* Minimum supported Rust version: 1.34 or later

View File

@ -10,12 +10,11 @@
//! uses cookies as identity storage.
//!
//! To access current request identity
//! [**Identity**](trait.Identity.html) extractor should be used.
//! [**Identity**](struct.Identity.html) extractor should be used.
//!
//! ```rust
//! use actix_web::middleware::identity::Identity;
//! use actix_web::middleware::identity::{CookieIdentityPolicy, IdentityService};
//! use actix_web::*;
//! use actix_identity::{Identity, CookieIdentityPolicy, IdentityService};
//!
//! fn index(id: Identity) -> String {
//! // access request identity
@ -39,7 +38,7 @@
//! fn main() {
//! let app = App::new().wrap(IdentityService::new(
//! // <- create identity middleware
//! CookieIdentityPolicy::new(&[0; 32]) // <- create cookie session backend
//! CookieIdentityPolicy::new(&[0; 32]) // <- create cookie identity policy
//! .name("auth-cookie")
//! .secure(false)))
//! .service(web::resource("/index.html").to(index))
@ -57,20 +56,17 @@ use futures::{Future, IntoFuture, Poll};
use serde::{Deserialize, Serialize};
use time::Duration;
use crate::cookie::{Cookie, CookieJar, Key, SameSite};
use crate::error::{Error, Result};
use crate::http::header::{self, HeaderValue};
use crate::service::{ServiceRequest, ServiceResponse};
use crate::{
dev::{Extensions, Payload},
FromRequest, HttpMessage, HttpRequest,
};
use actix_web::cookie::{Cookie, CookieJar, Key, SameSite};
use actix_web::dev::{Extensions, Payload, ServiceRequest, ServiceResponse};
use actix_web::error::{Error, Result};
use actix_web::http::header::{self, HeaderValue};
use actix_web::{FromRequest, HttpMessage, HttpRequest};
/// The extractor type to obtain your identity from a request.
///
/// ```rust
/// use actix_web::*;
/// use actix_web::middleware::identity::Identity;
/// use actix_identity::Identity;
///
/// fn index(id: Identity) -> Result<String> {
/// // access request identity
@ -134,7 +130,9 @@ struct IdentityItem {
}
/// Helper trait that allows to get Identity.
///
/// It could be used in middleware but identity policy must be set before any other middleware that needs identity
/// RequestIdentity is implemented both for `ServiceRequest` and `HttpRequest`.
pub trait RequestIdentity {
fn get_identity(&self) -> Option<String>;
}
@ -152,7 +150,7 @@ where
///
/// ```rust
/// # use actix_web::*;
/// use actix_web::middleware::identity::Identity;
/// use actix_identity::Identity;
///
/// fn index(id: Identity) -> String {
/// // access request identity
@ -199,7 +197,7 @@ pub trait IdentityPolicy: Sized + 'static {
///
/// ```rust
/// use actix_web::App;
/// use actix_web::middleware::identity::{CookieIdentityPolicy, IdentityService};
/// use actix_identity::{CookieIdentityPolicy, IdentityService};
///
/// fn main() {
/// let app = App::new().wrap(IdentityService::new(
@ -464,9 +462,8 @@ impl CookieIdentityInner {
/// # Example
///
/// ```rust
/// # extern crate actix_web;
/// use actix_web::middleware::identity::{CookieIdentityPolicy, IdentityService};
/// use actix_web::App;
/// use actix_identity::{CookieIdentityPolicy, IdentityService};
///
/// fn main() {
/// let app = App::new().wrap(IdentityService::new(
@ -612,13 +609,13 @@ impl IdentityPolicy for CookieIdentityPolicy {
#[cfg(test)]
mod tests {
use super::*;
use crate::http::StatusCode;
use crate::test::{self, TestRequest};
use crate::{web, App, HttpResponse};
use std::borrow::Borrow;
use super::*;
use actix_web::http::StatusCode;
use actix_web::test::{self, TestRequest};
use actix_web::{web, App, Error, HttpResponse};
const COOKIE_KEY_MASTER: [u8; 32] = [0; 32];
const COOKIE_NAME: &'static str = "actix_auth";
const COOKIE_LOGIN: &'static str = "test";
@ -739,8 +736,8 @@ mod tests {
f: F,
) -> impl actix_service::Service<
Request = actix_http::Request,
Response = ServiceResponse<actix_http::body::Body>,
Error = actix_http::Error,
Response = ServiceResponse<actix_web::body::Body>,
Error = Error,
> {
test::init_service(
App::new()

View File

@ -38,6 +38,7 @@ pub mod test;
pub mod ws;
pub use self::builder::ClientBuilder;
pub use self::connect::BoxedSocket;
pub use self::request::ClientRequest;
pub use self::response::{ClientResponse, JsonBody, MessageBody};

View File

@ -70,7 +70,7 @@
//! * `ssl` - enables ssl support via `openssl` crate, supports `http/2`
//! * `rust-tls` - enables ssl support via `rustls` crate, supports `http/2`
//! * `secure-cookies` - enables secure cookies support, includes `ring` crate as
//! dependency (default enabled)
//! dependency
//! * `brotli` - enables `brotli` compression support, requires `c`
//! compiler (default enabled)
//! * `flate2-zlib` - enables `gzip`, `deflate` compression support, requires

View File

@ -11,6 +11,3 @@ mod normalize;
pub use self::defaultheaders::DefaultHeaders;
pub use self::logger::Logger;
pub use self::normalize::NormalizePath;
#[cfg(feature = "secure-cookies")]
pub mod identity;