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
sourceimpl CookieIdentityPolicy
impl CookieIdentityPolicy
sourcepub fn new(key: &[u8]) -> CookieIdentityPolicy
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..
sourcepub fn name(self, value: impl Into<String>) -> CookieIdentityPolicy
pub fn name(self, value: impl Into<String>) -> CookieIdentityPolicy
Sets the name of issued cookies.
sourcepub fn path(self, value: impl Into<String>) -> CookieIdentityPolicy
pub fn path(self, value: impl Into<String>) -> CookieIdentityPolicy
Sets the Path
attribute of issued cookies.
sourcepub fn domain(self, value: impl Into<String>) -> CookieIdentityPolicy
pub fn domain(self, value: impl Into<String>) -> CookieIdentityPolicy
Sets the Domain
attribute of issued cookies.
sourcepub fn secure(self, value: bool) -> CookieIdentityPolicy
pub fn secure(self, value: bool) -> CookieIdentityPolicy
Sets the Secure
attribute of issued cookies.
sourcepub fn max_age(self, value: Duration) -> CookieIdentityPolicy
pub fn max_age(self, value: Duration) -> CookieIdentityPolicy
Sets the Max-Age
attribute of issued cookies.
sourcepub fn max_age_secs(self, seconds: i64) -> CookieIdentityPolicy
pub fn max_age_secs(self, seconds: i64) -> CookieIdentityPolicy
Sets the Max-Age
attribute of issued cookies with given number of seconds.
sourcepub fn http_only(self, http_only: bool) -> Self
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.
sourcepub fn same_site(self, same_site: SameSite) -> Self
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.
sourcepub fn visit_deadline(self, deadline: Duration) -> CookieIdentityPolicy
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.
sourcepub fn login_deadline(self, deadline: Duration) -> CookieIdentityPolicy
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
sourceimpl IdentityPolicy for CookieIdentityPolicy
impl IdentityPolicy for CookieIdentityPolicy
type ResponseFuture = Ready<Result<(), Error>>
type ResponseFuture = Ready<Result<(), Error>>
The return type of the middleware
sourcefn from_request(&self, req: &mut ServiceRequest) -> Self::Future
fn from_request(&self, req: &mut ServiceRequest) -> Self::Future
Parse the session from request and load data from a service identity.
sourcefn to_response<B>(
&self,
id: Option<String>,
changed: bool,
res: &mut ServiceResponse<B>
) -> Self::ResponseFuture
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more