Struct axum_csrf::CsrfConfig
source · pub struct CsrfConfig { /* private fields */ }
Expand description
This is the CSRF Config it is used to manage how we set the Restricted Cookie.
Implementations§
source§impl CsrfConfig
impl CsrfConfig
sourcepub fn new() -> Self
pub fn new() -> Self
Creates Default
configuration of CsrfConfig
.
This is equivalent to the CsrfConfig::default()
.
Set’s the csrf’s cookie’s domain name.
Examples
use axum_csrf::CsrfConfig;
let config = CsrfConfig::default().with_cookie_domain(Some("www.helpme.com".to_string()));
sourcepub fn with_lifetime(self, time: Duration) -> Self
pub fn with_lifetime(self, time: Duration) -> Self
Set’s the csrf’s lifetime (expiration time).
Examples
use axum_csrf::CsrfConfig;
use chrono::Duration;
let config = CsrfConfig::default().with_lifetime(Duration::days(32));
Set’s the csrf’s cookie’s name.
Examples
use axum_csrf::CsrfConfig;
let config = CsrfConfig::default().with_cookie_name("my_cookie");
Set’s the csrf’s cookie’s path.
This is used to deturmine when the cookie takes effect within the website path. Leave as default (“/”) for cookie to be used site wide.
Examples
use axum_csrf::CsrfConfig;
let config = CsrfConfig::default().with_cookie_path("/");
Set’s the csrf’s cookie’s Same Site Setting for Cross-Site restrictions.
Only works if Domain is also set to restrict it to that domain only.
Examples
use axum_csrf::CsrfConfig;
use cookie::SameSite;
let config = CsrfConfig::default().with_cookie_same_site(SameSite::Strict);
sourcepub fn with_http_only(self, is_set: bool) -> Self
pub fn with_http_only(self, is_set: bool) -> Self
Set’s the csrf’s cookie’s to http only.
Examples
use axum_csrf::CsrfConfig;
let config = CsrfConfig::default().with_http_only(false);
sourcepub fn with_secure(self, is_set: bool) -> Self
pub fn with_secure(self, is_set: bool) -> Self
Set’s the csrf’s secure flag for if it gets sent over https.
Examples
use axum_csrf::CsrfConfig;
let config = CsrfConfig::default().with_secure(true);
Set’s the csrf’s token length.
Examples
use axum_csrf::CsrfConfig;
let config = CsrfConfig::default().with_cookie_len(16);
sourcepub fn with_key(self, key: Option<Key>) -> Self
pub fn with_key(self, key: Option<Key>) -> Self
Set’s the csrf’s cookie encyption key enabling private cookies.
When Set it will enforce Private cookies across all Sessions. If you use Key::generate() it will make a new key each server reboot. To prevent this make and save a key to a config file for long term usage. For Extra Security Regenerate the key every so many months to a year.
Examples
use axum_csrf::{Key, CsrfConfig};
let config = CsrfConfig::default().with_key(Key::generate());
Trait Implementations§
source§impl Clone for CsrfConfig
impl Clone for CsrfConfig
source§fn clone(&self) -> CsrfConfig
fn clone(&self) -> CsrfConfig
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more