pub struct CsrfSynchronizerTokenLayer {
pub regenerate_token: RegenerateToken,
pub request_header: &'static str,
pub response_header: &'static str,
pub session_key: &'static str,
}
Expand description
Use CsrfSynchronizerTokenLayer::default()
to provide the middleware and configuration to axum’s service stack.
Use the provided methods to configure details, such as when tokens are regenerated, what request and response headers should be named, and under which key the token should be stored in the session.
Fields
regenerate_token: RegenerateToken
Configures when tokens are regenerated: Per session, per use or per request. See RegenerateToken
for details.
request_header: &'static str
Configures the request header name accepted by the middleware. Defaults to "X-CSRF-TOKEN"
.
This header is set on your JavaScript or WASM requests originating from the browser.
response_header: &'static str
Configures the response header name sent by the middleware. Defaults to "X-CSRF-TOKEN"
.
This header is received by your JavaScript or WASM code and its name must be used to extract the token from the HTTP response.
session_key: &'static str
Configures the key under which the middleware stores the server-side token in the session. Defaults to "_csrf_token"
.
Implementations
sourceimpl CsrfSynchronizerTokenLayer
impl CsrfSynchronizerTokenLayer
sourcepub fn regenerate(self, regenerate_token: RegenerateToken) -> Self
pub fn regenerate(self, regenerate_token: RegenerateToken) -> Self
Configure when tokens are regenerated: Per session, per use or per request. See RegenerateToken
for details.
sourcepub fn request_header(self, request_header: &'static str) -> Self
pub fn request_header(self, request_header: &'static str) -> Self
Configure a custom request header name accepted by the middleware. Defaults to "X-CSRF-TOKEN"
.
This header is set on your JavaScript or WASM requests originating from the browser.
sourcepub fn response_header(self, response_header: &'static str) -> Self
pub fn response_header(self, response_header: &'static str) -> Self
Configure a custom response header name sent by the middleware. Defaults to "X-CSRF-TOKEN"
.
This header is received by your JavaScript or WASM code and its name must be used to extract the token from the HTTP response.
sourcepub fn session_key(self, session_key: &'static str) -> Self
pub fn session_key(self, session_key: &'static str) -> Self
Configure a custom key under which the middleware stores the server-side token in the session. Defaults to "_csrf_token"
.
Trait Implementations
sourceimpl Clone for CsrfSynchronizerTokenLayer
impl Clone for CsrfSynchronizerTokenLayer
sourcefn clone(&self) -> CsrfSynchronizerTokenLayer
fn clone(&self) -> CsrfSynchronizerTokenLayer
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more