pub struct Auth<D, U = (), P = Nil> { /* private fields */ }Expand description
A configured auth instance. Cheap to clone (two Arcs).
D is the database adapter, U the app’s user fields, P the plugin list
(plugins![TwoFactor, Organization]).
Implementations§
Source§impl<D: Adapter, U: Fields, P: PluginSet> Auth<D, U, P>
impl<D: Adapter, U: Fields, P: PluginSet> Auth<D, U, P>
pub fn config(&self) -> &CoreConfig
pub fn schema(&self) -> &Schema
Sourcepub fn keys(&self) -> &Keys
pub fn keys(&self) -> &Keys
The keys derived from the configured secrets, as endpoints get them from
Ctx::keys: for app code that reads what fastauth encrypted, such as
Account::read_access_token.
pub fn adapter(&self) -> &D
pub fn migrator(&self) -> Migrator<'_, D>
Sourcepub async fn prune_verifications(&self) -> Result<u64, AuthError>
pub async fn prune_verifications(&self) -> Result<u64, AuthError>
Deletes every expired verification row (email verification and reset links,
OAuth states, codes) and answers how many. fastauth already deletes expired rows
before it stores a new one; call this, or
prune_verifications_every, to keep the table
small when few new rows arrive.
Sourcepub fn prune_verifications_every(&self, every: Duration) -> JoinHandle<()> ⓘ
pub fn prune_verifications_every(&self, every: Duration) -> JoinHandle<()> ⓘ
Runs prune_verifications every every on the
current Tokio runtime, first after one interval, until every clone of this Auth is
dropped or the handle is aborted. A failed run is logged and the next one runs on
time. Panics outside a Tokio runtime, as tokio::spawn does.
Sourcepub fn plugin<Pl: Plugin, I>(&self) -> &Plwhere
P: Has<Pl, I>,
pub fn plugin<Pl: Plugin, I>(&self) -> &Plwhere
P: Has<Pl, I>,
A registered plugin’s config. Doesn’t compile when the plugin isn’t registered.
Sourcepub async fn handle(&self, request: Request<Bytes>) -> Response
pub async fn handle(&self, request: Request<Bytes>) -> Response
Handles a request under base_path. Integrations call this.
The session for these request headers, plus Set-Cookie values the caller should
add to its response (refreshed or cleared cookies).
Sourcepub async fn get_session(
&self,
headers: &HeaderMap,
) -> Result<Option<SessionData<U, P>>, AuthError>
pub async fn get_session( &self, headers: &HeaderMap, ) -> Result<Option<SessionData<U, P>>, AuthError>
The session for these request headers (cookie, or any registered resolver).
Sourcepub async fn get_session_by_token(
&self,
token: &str,
) -> Result<Option<SessionData<U, P>>, AuthError>
pub async fn get_session_by_token( &self, token: &str, ) -> Result<Option<SessionData<U, P>>, AuthError>
The session for a raw token, e.g. from a WebSocket query string.
Trait Implementations§
Source§impl<D: Adapter, U: Fields, P: PluginSet> AuthInstance for Auth<D, U, P>
impl<D: Adapter, U: Fields, P: PluginSet> AuthInstance for Auth<D, U, P>
type Db = D
type UserFields = U
type Plugins = P
fn config(&self) -> &CoreConfig
fn api(&self) -> Api<'_, D>
Source§fn try_plugin<Pl: Plugin>(&self) -> Option<&Pl>
fn try_plugin<Pl: Plugin>(&self) -> Option<&Pl>
None when P isn’t registered. For code generic
over AuthInstance (an axum extractor) that can’t name the HasPlugin index; with a
concrete Auth, a plugin’s extension trait is the compile-checked way.