# CookieIdentityPolicy in actix_identity - Rust
Use cookies for request identity storage.
Keywords: rust, rustlang, rust-lang, CookieIdentityPolicy

# Struct actix_identity::CookieIdentityPolicy

source · [−]

    pub struct CookieIdentityPolicy(_);

Expand description

Use cookies for request identity storage.

See this page on MDN for details on cookie attributes.

## Examples

    use actix_web::App;
    use actix_identity::{CookieIdentityPolicy, IdentityService};

    // create cookie identity backend
    let policy = CookieIdentityPolicy::new(&[0; 32])
               .domain("www.rust-lang.org")
               .name("actix_auth")
               .path("/")
               .secure(true);

    let app = App::new()
        // wrap policy into identity middleware
        .wrap(IdentityService::new(policy));

## Implementations

source

### impl CookieIdentityPolicy

source

#### pub fn new(key: &[ u8 ]) -> CookieIdentityPolicy

Create new `CookieIdentityPolicy` instance.

Key argument is the private key for issued cookies. If this value is changed, all issued cookie identities are invalidated.

##### Panics

Panics if `key` is less than 32 bytes in length..

source

#### pub fn name(self, value: impl Into<String>) -> CookieIdentityPolicy

Sets the name of issued cookies.

source

#### pub fn path(self, value: impl Into<String>) -> CookieIdentityPolicy

Sets the `Path` attribute of issued cookies.

source

#### pub fn domain(self, value: impl Into<String>) -> CookieIdentityPolicy

Sets the `Domain` attribute of issued cookies.

source

#### pub fn secure(self, value: bool) -> CookieIdentityPolicy

Sets the `Secure` attribute of issued cookies.

source

#### pub fn max_age(self, value: Duration) -> CookieIdentityPolicy

Sets the `Max-Age` attribute of issued cookies.

source

#### pub fn max_age_secs(self, seconds: i64) -> CookieIdentityPolicy

Sets the `Max-Age` attribute of issued cookies with given number of seconds.

source

#### pub fn http_only(self, http_only: bool) -> Self

Sets the `HttpOnly` attribute of issued cookies.

By default, the `HttpOnly` attribute is omitted from issued cookies.

source

#### pub fn same_site(self, same_site: SameSite) -> Self

Sets the `SameSite` attribute of issued cookies.

By default, the `SameSite` attribute is omitted from issued cookies.

source

#### pub fn visit_deadline(self, deadline: Duration) -> CookieIdentityPolicy

Accepts only users who have visited within given deadline.

In other words, invalidate a login after some amount of inactivity. Using this feature causes updated cookies to be issued on each response in order to record the user’s last visitation timestamp.

By default, visit deadline is disabled.

source

#### pub fn login_deadline(self, deadline: Duration) -> CookieIdentityPolicy

Accepts only users who authenticated within the given deadline.

In other words, invalidate a login after some amount of time, regardless of activity. While `Max-Age` is useful in constraining the cookie lifetime, it could be extended manually; using this feature encodes the deadline directly into the issued cookies, making it immutable to users.

By default, login deadline is disabled.

## Trait Implementations

source

### impl IdentityPolicy for CookieIdentityPolicy

#### type Future = Ready<Result<Option<String>, Error>>

The return type of the middleware

#### type ResponseFuture = Ready<Result<(), Error>>

The return type of the middleware

source

#### fn from_request(&self, req: &mut ServiceRequest) -> Self::Future

Parse the session from request and load data from a service identity.

source

#### fn to_response<B>(
&self,
id: Option<String>,
changed: bool,
res: &mut ServiceResponse<B>
) -> Self::ResponseFuture

Write changes to response

## Auto Trait Implementations

### impl RefUnwindSafe for CookieIdentityPolicy

### impl !Send for CookieIdentityPolicy

### impl !Sync for CookieIdentityPolicy

### impl Unpin for CookieIdentityPolicy

### impl UnwindSafe for CookieIdentityPolicy

## Blanket Implementations

source

### impl<T> Any for T where
T: 'static + ?Sized,

source

#### fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more

source

### impl<T> Borrow<T> for T where
T: ?Sized,

const: unstable · source

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more

source

### impl<T> BorrowMut<T> for T where
T: ?Sized,

const: unstable · source

#### fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more

source

### impl<T> From<T> for T

const: unstable · source

#### fn from(t: T) -> T

Returns the argument unchanged.

source

### impl<T> Instrument for T

source

#### fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided `Span`, returning an `Instrumented` wrapper. Read more

source

#### fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current `Span`, returning an `Instrumented` wrapper. Read more

source

### impl<T, U> Into<U> for T where
U: From<T>,

const: unstable · source

#### fn into(self) -> U

Calls `U::from(self)`.

That is, this conversion is whatever the implementation of `From<T> for U` chooses to do.

source

### impl<T> Same<T> for T

#### type Output = T

Should always be `Self`

source

### impl<T, U> TryFrom<U> for T where
U: Into<T>,

#### type Error = Infallible

The type returned in the event of a conversion error.

const: unstable · source

#### fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.

source

### impl<T, U> TryInto<U> for T where
U: TryFrom<T>,

#### type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

const: unstable · source

#### fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

### impl<V, T> VZip<V> for T where
V: MultiLane<T>,

#### fn vzip(self) -> V

source

### impl<T> WithSubscriber for T

source

#### fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,

Attaches the provided `Subscriber` to this type, returning a `WithDispatch` wrapper. Read more

source

#### fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper. Read more