Skip to content

Commit

Permalink
move identity service separate crate
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Jun 12, 2019
1 parent ee76983 commit ff724e2
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 32 deletions.
6 changes: 4 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Changes

## [1.0.x] - 2019-xx-xx
## [1.0.1] - 2019-06-xx

### Add

* Add `middleware::identity::RequestIdentity` trait to `get_identity` from `HttpMessage`.

### Changes

### Fixed
* Disable default feature `secure-cookies`.

* Move identity middleware to `actix-identity` crate.


## [1.0.0] - 2019-06-05
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ members = [
"actix-files",
"actix-framed",
"actix-session",
"actix-identity",
"actix-multipart",
"actix-web-actors",
"actix-web-codegen",
"test-server",
]

[features]
default = ["brotli", "flate2-zlib", "secure-cookies", "client", "fail"]
default = ["brotli", "flate2-zlib", "client", "fail"]

# http client
client = ["awc"]
Expand Down Expand Up @@ -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"
Expand Down
17 changes: 17 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions actix-identity/CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changes

## [0.1.0] - 2019-06-xx

* Move identity middleware to separate crate
29 changes: 29 additions & 0 deletions actix-identity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "actix-identity"
version = "0.1.0"
authors = ["Nikolay Kim <[email protected]>"]
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"
1 change: 1 addition & 0 deletions actix-identity/LICENSE-APACHE
1 change: 1 addition & 0 deletions actix-identity/LICENSE-MIT
9 changes: 9 additions & 0 deletions actix-identity/README.md
Original file line number Diff line number Diff line change
@@ -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
45 changes: 21 additions & 24 deletions src/middleware/identity.rs → actix-identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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>;
}
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions awc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/middleware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit ff724e2

Please sign in to comment.