Struct axum_login::AuthSession
source ยท pub struct AuthSession<Backend: AuthnBackend> {
pub user: Option<Backend::User>,
pub backend: Backend,
/* 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::User>
The user associated by the backend. None
when not logged in.
backend: Backend
The authentication and authorization backend.
Implementationsยง
sourceยงimpl<Backend: AuthnBackend> AuthSession<Backend>
impl<Backend: AuthnBackend> AuthSession<Backend>
sourcepub async fn authenticate(
&self,
creds: Backend::Credentials
) -> Result<Option<Backend::User>, Error<Backend>>
pub async fn authenticate( &self, creds: Backend::Credentials ) -> Result<Option<Backend::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 + AuthnBackend> Clone for AuthSession<Backend>
impl<Backend: Clone + AuthnBackend> 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 more