pub struct Csrf<Inner>(/* private fields */);
Expand description
This extractor wraps another extractor that returns some inner type that holds a CSRF token, and performs validation on the token. If the token is missing or invalid, then the extractor will return an error.
use actix_csrf::extractor::{Csrf, CsrfGuarded, CsrfToken};
use actix_web::{post, Responder};
use actix_web::web::Form;
use serde::Deserialize;
#[derive(Deserialize)]
struct Login {
csrf: CsrfToken,
email: String,
password: String,
}
impl CsrfGuarded for Login {
fn csrf_token(&self) -> &CsrfToken {
&self.csrf
}
}
#[post("/login")]
async fn login(form: Csrf<Form<Login>>) -> impl Responder {
// If we got here, then the CSRF token passed validation!
format!("hello, {}, your password is {}", &form.email, &form.password)
}
Implementations§
Source§impl<Inner> Csrf<Inner>
impl<Inner> Csrf<Inner>
Sourcepub fn into_inner(self) -> Inner
pub fn into_inner(self) -> Inner
Deconstruct to an inner value
Trait Implementations§
Source§impl<Inner> FromRequest for Csrf<Inner>where
Inner: FromRequest + CsrfGuarded,
impl<Inner> FromRequest for Csrf<Inner>where
Inner: FromRequest + CsrfGuarded,
Source§type Error = CsrfExtractorError<<Inner as FromRequest>::Error>
type Error = CsrfExtractorError<<Inner as FromRequest>::Error>
The associated error which can be returned.
Source§type Future = CsrfExtractorFuture<<Inner as FromRequest>::Future>
type Future = CsrfExtractorFuture<<Inner as FromRequest>::Future>
Future that resolves to a Self.
Source§fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
Create a Self from request parts asynchronously.
Source§impl<Inner: Ord> Ord for Csrf<Inner>
impl<Inner: Ord> Ord for Csrf<Inner>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<Inner: PartialOrd> PartialOrd for Csrf<Inner>
impl<Inner: PartialOrd> PartialOrd for Csrf<Inner>
impl<Inner: Eq> Eq for Csrf<Inner>
impl<Inner> StructuralPartialEq for Csrf<Inner>
Auto Trait Implementations§
impl<Inner> Freeze for Csrf<Inner>where
Inner: Freeze,
impl<Inner> RefUnwindSafe for Csrf<Inner>where
Inner: RefUnwindSafe,
impl<Inner> Send for Csrf<Inner>where
Inner: Send,
impl<Inner> Sync for Csrf<Inner>where
Inner: Sync,
impl<Inner> Unpin for Csrf<Inner>where
Inner: Unpin,
impl<Inner> UnwindSafe for Csrf<Inner>where
Inner: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CallHasher for T
impl<T> CallHasher for T
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.