Skip to main content

Auth

Struct Auth 

Source
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>

Source

pub fn config(&self) -> &CoreConfig

Source

pub fn schema(&self) -> &Schema

Source

pub fn adapter(&self) -> &D

Source

pub fn migrator(&self) -> Migrator<'_, D>

Source

pub fn plugin<Pl: Plugin, I>(&self) -> &Pl
where P: Has<Pl, I>,

A registered plugin’s config. Doesn’t compile when the plugin isn’t registered.

Source

pub fn api(&self) -> Api<'_, D>

Server-side calls to endpoints: no HTTP, no JSON.

Source

pub async fn handle(&self, request: Request<Bytes>) -> Response

Handles a request under base_path. Integrations call this.

Source

pub async fn session_with_cookies( &self, headers: &HeaderMap, ) -> (Result<Option<SessionData<U, P>>, AuthError>, Vec<HeaderValue>)

The session for these request headers, plus Set-Cookie values the caller should add to its response (refreshed or cleared cookies).

Source

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).

Source

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>

Source§

type Db = D

Source§

type UserFields = U

Source§

type Plugins = P

Source§

fn config(&self) -> &CoreConfig

Source§

fn api(&self) -> Api<'_, D>

Source§

fn try_plugin<Pl: Plugin>(&self) -> Option<&Pl>

A registered plugin’s config, or 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.
Source§

fn handle( &self, request: Request<Bytes>, ) -> impl Future<Output = Response> + Send

Source§

fn session_with_cookies( &self, headers: &HeaderMap, ) -> impl Future<Output = (Result<Option<SessionData<U, P>>, AuthError>, Vec<HeaderValue>)> + Send

Source§

impl<D, U, P> Clone for Auth<D, U, P>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D, U, P> Debug for Auth<D, U, P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<D: Adapter, U: Fields, P: Has<Pl, I>, Pl: Plugin, I> HasPlugin<Pl, I> for Auth<D, U, P>

Source§

fn plugin_arc(&self) -> &Arc<Pl> ⓘ

Auto Trait Implementations§

§

impl<D, U = (), P = Nil> !RefUnwindSafe for Auth<D, U, P>

§

impl<D, U = (), P = Nil> !UnwindSafe for Auth<D, U, P>

§

impl<D, U, P> Forget for Auth<D, U, P>

§

impl<D, U, P> Freeze for Auth<D, U, P>
where Arc<Shared<D>>: Freeze, Arc<P>: Freeze, PhantomData<fn() -> U>: Freeze,

§

impl<D, U, P> Move for Auth<D, U, P>

§

impl<D, U, P> Send for Auth<D, U, P>
where Arc<Shared<D>>: Send, Arc<P>: Send, PhantomData<fn() -> U>: Send,

§

impl<D, U, P> Sync for Auth<D, U, P>
where Arc<Shared<D>>: Sync, Arc<P>: Sync, PhantomData<fn() -> U>: Sync,

§

impl<D, U, P> Unpin for Auth<D, U, P>
where Arc<Shared<D>>: Unpin, Arc<P>: Unpin, PhantomData<fn() -> U>: Unpin,

§

impl<D, U, P> UnsafeUnpin for Auth<D, U, P>
where Arc<Shared<D>>: UnsafeUnpin, Arc<P>: UnsafeUnpin, PhantomData<fn() -> U>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more