CookieIdentityPolicy

Struct CookieIdentityPolicy 

Source
pub struct CookieIdentityPolicy(/* private fields */);
Expand description

Use cookies for request identity storage.

The constructors take a key as an argument. This is the private key for cookie - when this value is changed, all identities are lost. The constructors will panic if the key is less than 32 bytes in length.

§Example

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

let app = App::new().wrap(IdentityService::new(
    // <- create identity middleware
    CookieIdentityPolicy::new(&[0; 32])  // <- construct cookie policy
           .domain("www.rust-lang.org")
           .name("actix_auth")
           .path("/")
           .secure(true),
));

Implementations§

Source§

impl CookieIdentityPolicy

Source

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

Construct new CookieIdentityPolicy instance.

Panics if key length is less than 32 bytes.

Source

pub fn path<S>(self, value: S) -> CookieIdentityPolicy
where S: Into<String>,

Sets the path field in the session cookie being built.

Source

pub fn name<S>(self, value: S) -> CookieIdentityPolicy
where S: Into<String>,

Sets the name field in the session cookie being built.

Source

pub fn domain<S>(self, value: S) -> CookieIdentityPolicy
where S: Into<String>,

Sets the domain field in the session cookie being built.

Source

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

Sets the secure field in the session cookie being built.

If the secure field is set, a cookie will only be transmitted when the connection is secure - i.e. https

Source

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

Sets the max-age field in the session cookie being built with given number of seconds.

Source

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

Sets the max-age field in the session cookie being built with time::Duration.

Source

pub fn http_only(self, http_only: bool) -> CookieIdentityPolicy

Sets the http_only field in the session cookie being built.

Source

pub fn same_site(self, same_site: SameSite) -> CookieIdentityPolicy

Sets the same_site field in the session cookie being built.

Source

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

Accepts only users whose cookie has been seen before the given deadline

By default visit deadline is disabled.

Source

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

Accepts only users which has been authenticated before the given deadline

By default login deadline is disabled.

Trait Implementations§

Source§

impl IdentityPolicy for CookieIdentityPolicy

Source§

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

The return type of the middleware
Source§

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

The return type of the middleware
Source§

fn from_request( &self, req: &mut ServiceRequest, ) -> <CookieIdentityPolicy as IdentityPolicy>::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>, ) -> <CookieIdentityPolicy as IdentityPolicy>::ResponseFuture

Write changes to response

Auto Trait Implementations§

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,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

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> 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>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
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>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,