Skip to main content

PluginBuilder

Struct PluginBuilder 

Source
pub struct PluginBuilder<'r, D> { /* private fields */ }
Expand description

What Plugin::init (and Builder::configure) registers things with.

Implementations§

Source§

impl<D: Adapter> PluginBuilder<'_, D>

Source

pub fn owner(&self) -> &'static str

Id of the plugin being initialised ("app" for Builder::configure).

Source

pub fn schema(&mut self) -> &mut SchemaBuilder

Adds tables or columns (normally done in Plugin::schema).

Source

pub fn endpoint<E: Endpoint<D>>(&mut self, endpoint: E) -> &mut Self

Source

pub fn server_endpoint<E: Endpoint<D>>(&mut self) -> &mut Self

Declares an endpoint with no HTTP route, one only the server API calls through auth.api().call(..), so hooks may target it like a routed one.

Source

pub fn hook<E: Endpoint<D>>(&mut self) -> HookBuilder<'_, D, E>

Hooks around endpoint E, for every caller: app.hook::<SignUpEmail>().before(..).

Source

pub fn sign_in_gate<F, Fut>(&mut self, gate: F) -> &mut Self
where F: Fn(HookCtx<D>, SignInAttempt) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Gate, AuthError>> + Send + 'static,

Runs after credentials check out and before a session exists, for every sign-in method. Gates run in registration order. The gate belongs to owner: when it answers Gate::Challenge, this plugin finishes the sign-in with Internal::complete_sign_in and its own id.

Source

pub fn session_gate<F, Fut>(&mut self, gate: F) -> &mut Self
where F: Fn(HookCtx<D>, SessionView, SessionUse) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), AuthError>> + Send + 'static,

Checks every session a request resolves to (cookie, cookie cache, bearer token, API key) and every Ctx::sensitive_session. Err refuses the session: the request fails with that error. Unlike sign_in_gate, which judges a sign-in once, this runs on every request, so keep it cheap; the SessionUse says which check it is.

Source

pub fn fixed_session_expiry( &mut self, fixed: impl Fn(&SessionView) -> bool + Send + Sync + 'static, ) -> &mut Self

Marks sessions the refresh must not extend: when fixed answers true for a session, it keeps the expires_at it was given, whatever update_age. For sessions a plugin creates with a deliberately short life, such as admin’s impersonation sessions.

Source

pub fn session_resolver( &mut self, resolver: impl SessionResolver<D>, ) -> &mut Self

Turns non-cookie credentials (bearer tokens, API keys) into a session.

Source

pub fn on_response( &mut self, hook: impl Fn(&Ctx<D>, &mut Response) + Send + Sync + 'static, ) -> &mut Self

Runs on the HTTP response of every routed endpoint, after its cookies and headers are set, in registration order. For headers derived from the response itself, like a bearer plugin copying the session cookie into set-auth-token. Server API calls don’t run it.

Source

pub fn on_session_created<F, Fut>(&mut self, hook: F) -> &mut Self
where F: Fn(HookCtx<D>, SessionView) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), AuthError>> + Send + 'static,

Runs inside the request right after Internal::create_session stored a session and set its cookies, for every way a session is created (sign-in and sign-up of any method, a finished challenge, impersonation). In registration order. The context still carries the request’s headers, so the session cookie the request came with is the previous session; hooks may set cookies and query the database. An error fails the request, though the session already exists.

Unlike the SessionCreated event, which runs after the endpoint without the request, this is for plugins that react to a sign-in in place, like linking an anonymous user or remembering a device session.

Source

pub fn on<Ev, F, Fut>(&mut self, handler: F) -> &mut Self
where Ev: Event, F: Fn(Ev, Ctx<D>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), AuthError>> + Send + 'static,

Runs after any endpoint that emitted Ev succeeds. Errors are logged, not returned.

Source

pub fn rate_limit( &mut self, pattern: impl Into<String>, limit: Limit, ) -> &mut Self

A rate-limit rule for a path pattern (/two-factor/*). App rules win over plugin rules.

Source

pub fn errors<E: ErrorCodes>(&mut self) -> &mut Self

Registers error codes so two plugins can’t claim the same one.

Auto Trait Implementations§

§

impl<'r, D> !RefUnwindSafe for PluginBuilder<'r, D>

§

impl<'r, D> !UnwindSafe for PluginBuilder<'r, D>

§

impl<'r, D> Forget for PluginBuilder<'r, D>

§

impl<'r, D> Freeze for PluginBuilder<'r, D>
where &'r mut Registry<D>: Freeze,

§

impl<'r, D> Move for PluginBuilder<'r, D>

§

impl<'r, D> Send for PluginBuilder<'r, D>
where &'r mut Registry<D>: Send,

§

impl<'r, D> Sync for PluginBuilder<'r, D>
where &'r mut Registry<D>: Sync,

§

impl<'r, D> Unpin for PluginBuilder<'r, D>
where &'r mut Registry<D>: Unpin,

§

impl<'r, D> UnsafeUnpin for PluginBuilder<'r, D>
where &'r mut Registry<D>: 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> 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, 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