pub struct AuthUser(pub Arc<AuthIdentity>);Expand description
This is the crate users will import. It re-exports the internal pieces use nestforge::{NestForgeFactory, ModuleDefinition, Container}; AuthUser Extractor
A request extractor that provides mandatory authentication. Fails with 401 Unauthorized if no authenticated identity is present.
§Usage
async fn handler(user: AuthUser) -> impl IntoResponse {
format!("Hello, {}", user.subject)
}Tuple Fields§
§0: Arc<AuthIdentity>Implementations§
Source§impl AuthUser
impl AuthUser
pub fn into_inner(self) -> Arc<AuthIdentity>
pub fn value(&self) -> &AuthIdentity
Methods from Deref<Target = AuthIdentity>§
Sourcepub fn has_role(&self, role: &str) -> bool
pub fn has_role(&self, role: &str) -> bool
Checks if the identity has a specific role.
§Arguments
role: The role name to check
Returns true if the role is present in the identity’s roles.
Sourcepub fn require_role(&self, role: &str) -> Result<(), HttpException>
pub fn require_role(&self, role: &str) -> Result<(), HttpException>
Requires a specific role, returning an error if not present.
§Arguments
role: The required role name
Returns Ok if the role is present, or a forbidden HttpException if not.
Trait Implementations§
Source§impl<S> FromRequestParts<S> for AuthUser
impl<S> FromRequestParts<S> for AuthUser
Source§type Rejection = HttpException
type Rejection = HttpException
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§async fn from_request_parts(
parts: &mut Parts,
_state: &S,
) -> Result<AuthUser, <AuthUser as FromRequestParts<S>>::Rejection>
async fn from_request_parts( parts: &mut Parts, _state: &S, ) -> Result<AuthUser, <AuthUser as FromRequestParts<S>>::Rejection>
Perform the extraction.
Auto Trait Implementations§
impl Freeze for AuthUser
impl RefUnwindSafe for AuthUser
impl Send for AuthUser
impl Sync for AuthUser
impl Unpin for AuthUser
impl UnsafeUnpin for AuthUser
impl UnwindSafe for AuthUser
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,
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.