pub struct AuthenticatedUser<C>(pub C);Available on crate features
auth and auth-axum only.Expand description
Extractor for authenticated requests.
Extracts and validates the bearer token from the Authorization header, returning the claims on success.
§Example
ⓘ
use allframe_core::auth::AuthenticatedUser;
async fn handler(AuthenticatedUser(claims): AuthenticatedUser<MyClaims>) -> String {
format!("User ID: {}", claims.sub)
}§Extracting Optional Auth
Wrap in Option to make auth optional:
ⓘ
async fn handler(auth: Option<AuthenticatedUser<MyClaims>>) -> String {
match auth {
Some(AuthenticatedUser(claims)) => format!("Hello, {}", claims.sub),
None => "Hello, anonymous!".to_string(),
}
}Tuple Fields§
§0: CImplementations§
Source§impl<C> AuthenticatedUser<C>
impl<C> AuthenticatedUser<C>
Sourcepub fn into_inner(self) -> C
pub fn into_inner(self) -> C
Unwrap into the inner claims.
Trait Implementations§
Source§impl<C: Clone> Clone for AuthenticatedUser<C>
impl<C: Clone> Clone for AuthenticatedUser<C>
Source§fn clone(&self) -> AuthenticatedUser<C>
fn clone(&self) -> AuthenticatedUser<C>
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<C: Debug> Debug for AuthenticatedUser<C>
impl<C: Debug> Debug for AuthenticatedUser<C>
Auto Trait Implementations§
impl<C> Freeze for AuthenticatedUser<C>where
C: Freeze,
impl<C> RefUnwindSafe for AuthenticatedUser<C>where
C: RefUnwindSafe,
impl<C> Send for AuthenticatedUser<C>where
C: Send,
impl<C> Sync for AuthenticatedUser<C>where
C: Sync,
impl<C> Unpin for AuthenticatedUser<C>where
C: Unpin,
impl<C> UnwindSafe for AuthenticatedUser<C>where
C: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request