pub trait Identity:
Send
+ Sync
+ 'static {
// Required method
fn is_guest(&self) -> bool;
// Provided methods
fn csrf_binding(&self) -> Option<&[u8]> { ... }
fn set_cookie(&self) -> Option<&str> { ... }
}Expand description
Who is asking. A request that reaches a handler always carries one, possibly a guest.
use web_net::Identity;
struct User { session: Option<Vec<u8>> }
impl Identity for User {
fn is_guest(&self) -> bool { self.session.is_none() }
fn csrf_binding(&self) -> Option<&[u8]> { self.session.as_deref() }
}
let ann = User { session: Some(b"s-41".to_vec()) };
assert!(!ann.is_guest());
assert_eq!(ann.csrf_binding(), Some(&b"s-41"[..]));
assert_eq!(ann.set_cookie(), None); // the defaultRequired Methods§
Provided Methods§
Sourcefn csrf_binding(&self) -> Option<&[u8]>
fn csrf_binding(&self) -> Option<&[u8]>
The value CSRF tokens are bound to: the session id, or a pre-session
id for a guest. None means no binding exists, and an unsafe method
on a CSRF-protected route is refused.
A Set-Cookie value the gate wants on the reply (a dead session’s
cookie cleared, a pre-session id set). App::respond
writes it on every exit after authentication, once; when the caller
passes an identity to respond, it authenticated and writes its own. A reply that carries it is never
reported as keepable by a cache.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".