pub struct AuthenticatedUser {
pub sub: String,
pub email: Option<String>,
pub roles: Vec<String>,
pub claims: Value,
}Expand description
Represents an authenticated user extracted from a validated JWT token.
Fields§
§sub: StringSubject claim (“sub”) - unique user identifier.
email: Option<String>Email claim (“email”), if present in the token.
roles: Vec<String>Roles extracted from the token claims.
claims: ValueRaw claims for advanced access.
Implementations§
Trait Implementations§
Source§impl Clone for AuthenticatedUser
impl Clone for AuthenticatedUser
Source§fn clone(&self) -> AuthenticatedUser
fn clone(&self) -> AuthenticatedUser
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AuthenticatedUser
impl Debug for AuthenticatedUser
Source§impl<'de> Deserialize<'de> for AuthenticatedUser
impl<'de> Deserialize<'de> for AuthenticatedUser
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<S> FromRequestParts<S> for AuthenticatedUser
Axum extractor implementation for AuthenticatedUser.
impl<S> FromRequestParts<S> for AuthenticatedUser
Axum extractor implementation for AuthenticatedUser.
This extracts the JWT from the Authorization: Bearer <token> header,
validates it using the JwtValidator from the application state,
and returns an AuthenticatedUser on success.
The application state must implement FromRef<S> for Arc<JwtValidator>.
For custom identity types, use extract_jwt_identity to implement
FromRequestParts with minimal boilerplate.
§Example
ⓘ
async fn protected_handler(user: AuthenticatedUser) -> impl IntoResponse {
format!("Hello, {}!", user.sub)
}Source§impl Identity for AuthenticatedUser
impl Identity for AuthenticatedUser
Auto Trait Implementations§
impl Freeze for AuthenticatedUser
impl RefUnwindSafe for AuthenticatedUser
impl Send for AuthenticatedUser
impl Sync for AuthenticatedUser
impl Unpin for AuthenticatedUser
impl UnsafeUnpin for AuthenticatedUser
impl UnwindSafe for AuthenticatedUser
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.