pub struct AuthUser {
pub id: String,
pub account: String,
pub label: String,
pub is_admin: bool,
pub sequence_number: i64,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub csrf_token: String,
pub csrf_via_header_verified: bool,
}
Expand description
Authenticated user information, available as an Axum extractor
This struct represents an authenticated user and can be used as an extractor in Axum route handlers. When used as an extractor, it checks for a valid session cookie and automatically verifies CSRF token requirements for state-changing methods (POST, PUT, DELETE, PATCH).
§Fields
id
- Unique user identifieraccount
- User’s account name (email or username)label
- User’s display nameis_admin
- Whether the user has admin privilegessequence_number
- User version for tracking account changescreated_at
- When the user account was createdupdated_at
- When the user account was last updatedcsrf_token
- CSRF token associated with the user’s sessioncsrf_via_header_verified
- Whether CSRF token was verified via header
§Example
use axum::{routing::get, Router};
use oauth2_passkey_axum::AuthUser;
async fn protected_handler(user: AuthUser) -> String {
format!("Hello, {}!", user.label)
}
let app: Router = Router::new()
.route("/protected", get(protected_handler));
Fields§
§id: String
Unique user identifier
account: String
User’s account name (email or username)
label: String
User’s display name
is_admin: bool
Whether the user has admin privileges
sequence_number: i64
User version for tracking account changes
created_at: DateTime<Utc>
When the user account was created
updated_at: DateTime<Utc>
When the user account was last updated
csrf_token: String
CSRF token associated with the user’s session
csrf_via_header_verified: bool
Whether CSRF token was verified via header
Trait Implementations§
Source§impl From<&AuthUser> for SessionUser
impl From<&AuthUser> for SessionUser
Source§impl From<User> for AuthUser
impl From<User> for AuthUser
Source§fn from(session_user: SessionUser) -> Self
fn from(session_user: SessionUser) -> Self
Converts to this type from the input type.
Source§impl<B> FromRequestParts<B> for AuthUser
impl<B> FromRequestParts<B> for AuthUser
Source§impl<B> OptionalFromRequestParts<B> for AuthUser
impl<B> OptionalFromRequestParts<B> for AuthUser
Auto Trait Implementations§
impl Freeze for AuthUser
impl RefUnwindSafe for AuthUser
impl Send for AuthUser
impl Sync for AuthUser
impl Unpin for AuthUser
impl UnwindSafe for AuthUser
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more