pub struct AuthSession<Backend>where
Backend: AuthnBackend,{
pub user: Option<<Backend as AuthnBackend>::User>,
pub backend: Backend,
pub session: Session,
/* private fields */
}Expand description
A specialized session for identification, authentication, and authorization of users associated with a backend.
The session is generic over some backend which implements AuthnBackend.
The backend may also implement AuthzBackend,
in which case it will also supply authorization methods.
Methods for authenticating the session and logging a user in are provided.
Generally this session will be used in the context of some authentication workflow, for example via a frontend login form. There a user would provide their credentials, such as username and password, and via the backend the session would authenticate those credentials.
Once the supplied credentials have been authenticated, a user will be returned. In the case the credentials are invalid, no user will be returned. When we do have a user, it’s then possible to set the state of the session so that the user is logged in.
Fields§
§user: Option<<Backend as AuthnBackend>::User>The user associated by the backend. None when not logged in.
backend: BackendThe authentication and authorization backend.
session: SessionThe underlying session.
Implementations§
Source§impl<Backend> AuthSession<Backend>where
Backend: AuthnBackend,
impl<Backend> AuthSession<Backend>where
Backend: AuthnBackend,
Sourcepub async fn authenticate(
&self,
creds: <Backend as AuthnBackend>::Credentials,
) -> Result<Option<<Backend as AuthnBackend>::User>, Error<Backend>>
pub async fn authenticate( &self, creds: <Backend as AuthnBackend>::Credentials, ) -> Result<Option<<Backend as AuthnBackend>::User>, Error<Backend>>
Verifies the provided credentials via the backend returning the
authenticated user if valid and otherwise None.
Trait Implementations§
Source§impl<Backend> Clone for AuthSession<Backend>
impl<Backend> Clone for AuthSession<Backend>
Source§fn clone(&self) -> AuthSession<Backend>
fn clone(&self) -> AuthSession<Backend>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Backend> Debug for AuthSession<Backend>
impl<Backend> Debug for AuthSession<Backend>
Source§impl<S, Backend> FromRequestParts<S> for AuthSession<Backend>
impl<S, Backend> FromRequestParts<S> for AuthSession<Backend>
Source§type Rejection = (StatusCode, &'static str)
type Rejection = (StatusCode, &'static str)
Source§async fn from_request_parts(
parts: &mut Parts,
_state: &S,
) -> Result<AuthSession<Backend>, <AuthSession<Backend> as FromRequestParts<S>>::Rejection>
async fn from_request_parts( parts: &mut Parts, _state: &S, ) -> Result<AuthSession<Backend>, <AuthSession<Backend> as FromRequestParts<S>>::Rejection>
Auto Trait Implementations§
impl<Backend> Freeze for AuthSession<Backend>where
Backend: Freeze,
<Backend as AuthnBackend>::User: Freeze,
<<Backend as AuthnBackend>::User as AuthUser>::Id: Freeze,
impl<Backend> !RefUnwindSafe for AuthSession<Backend>
impl<Backend> Send for AuthSession<Backend>
impl<Backend> Sync for AuthSession<Backend>
impl<Backend> Unpin for AuthSession<Backend>where
Backend: Unpin,
<Backend as AuthnBackend>::User: Unpin,
<<Backend as AuthnBackend>::User as AuthUser>::Id: Unpin,
impl<Backend> UnsafeUnpin for AuthSession<Backend>where
Backend: UnsafeUnpin,
<Backend as AuthnBackend>::User: UnsafeUnpin,
<<Backend as AuthnBackend>::User as AuthUser>::Id: UnsafeUnpin,
impl<Backend> !UnwindSafe for AuthSession<Backend>
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
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
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>>
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>
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>
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