pub struct RequiredAuthentication {
pub user: ResponseUserDto,
pub team: ResponseTeamDto,
pub services: Services,
pub token: String,
}Expand description
An extractor that handles authentication and authorization for protected routes.
This extractor validates the JWT token from the Authorization header, retrieves the associated user and team information, and checks subscription status. It is used as a guard for routes that require authenticated access.
§Fields
user- The authenticated user’s informationteam- The team information associated with the authenticated userservices- Access to application servicestoken- The validated JWT token string
§Example
async fn protected_route(
RequiredAuthentication { user, team, .. }: RequiredAuthentication
) -> Result<impl Response, Error> {
// Handle authenticated request
}Fields§
§user: ResponseUserDto§team: ResponseTeamDto§services: Services§token: StringTrait Implementations§
source§impl<S> FromRequestParts<S> for RequiredAuthentication
impl<S> FromRequestParts<S> for RequiredAuthentication
source§fn from_request_parts<'life0, 'life1, 'async_trait>(
parts: &'life0 mut Parts,
state: &'life1 S,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn from_request_parts<'life0, 'life1, 'async_trait>(
parts: &'life0 mut Parts,
state: &'life1 S,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Implementation of the FromRequestParts trait to enable automatic extraction of authentication information from incoming requests.
This implementation:
- Extracts the services from request extensions
- Validates the Authorization header format (Bearer token)
- Extracts and validates the JWT token
- Retrieves the associated user and team information
- Verifies subscription status
§Errors
Returns Error::Unauthorized in cases of:
- Missing or malformed Authorization header
- Invalid token format
- Invalid or expired JWT token
- User not found
- Team not found
Returns Error::PaymentRequired if:
- Team’s subscription has expired (except for free plan teams)
Auto Trait Implementations§
impl Freeze for RequiredAuthentication
impl !RefUnwindSafe for RequiredAuthentication
impl Send for RequiredAuthentication
impl Sync for RequiredAuthentication
impl Unpin for RequiredAuthentication
impl !UnwindSafe for RequiredAuthentication
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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
§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 moreCreates a shared type from an unshared type.
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.