pub struct CsrfLayer {
pub regenerate_token: RegenerateToken,
pub request_header: &'static str,
pub response_header: &'static str,
pub session_key: &'static str,
}
Expand description
Use CsrfLayer::new()
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§
Source§impl CsrfLayer
impl CsrfLayer
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new CSRF synchronizer token layer to inject into your middleware stack using
axum::Router::layer()
.
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"
.