pub struct Auth { /* private fields */ }Expand description
The authentication state of the current request.
Present on every context, authenticated or not.
Implementations§
Source§impl Auth
impl Auth
Sourcepub fn jwt() -> JwtGuard
pub fn jwt() -> JwtGuard
Middleware that requires a valid bearer token.
Resolves Jwt from the container, so the signing key is configured
once in providers().
Sourcepub fn optional_jwt() -> JwtGuard
pub fn optional_jwt() -> JwtGuard
As Auth::jwt, but allows anonymous requests through. Useful for
endpoints that render differently when signed in.
Sourcepub fn session() -> SessionGuard
pub fn session() -> SessionGuard
Cookie-backed sessions.
Loads the session, exposes it as ctx.session, sets ctx.auth from the
session’s subject, and persists any changes afterwards. Anonymous
requests pass through — a session is how a user becomes
authenticated, so refusing them would leave nowhere to log in.
Requires a SessionStore bound in providers().
pub fn check(&self) -> bool
pub fn try_identity(&self) -> Option<&Identity>
Sourcepub fn id<T: FromStr>(&self) -> Result<T>
pub fn id<T: FromStr>(&self) -> Result<T>
The authenticated subject parsed into the app’s id type, or a 401.
pub fn set(&mut self, identity: Identity)
pub fn forget(&mut self)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Auth
impl RefUnwindSafe for Auth
impl Send for Auth
impl Sync for Auth
impl Unpin for Auth
impl UnsafeUnpin for Auth
impl UnwindSafe for Auth
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