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>
impl<D: Adapter> PluginBuilder<'_, D>
Sourcepub fn owner(&self) -> &'static str
pub fn owner(&self) -> &'static str
Id of the plugin being initialised ("app" for Builder::configure).
Sourcepub fn schema(&mut self) -> &mut SchemaBuilder
pub fn schema(&mut self) -> &mut SchemaBuilder
Adds tables or columns (normally done in Plugin::schema).
pub fn endpoint<E: Endpoint<D>>(&mut self, endpoint: E) -> &mut Self
Sourcepub fn server_endpoint<E: Endpoint<D>>(&mut self) -> &mut Self
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.
Sourcepub fn hook<E: Endpoint<D>>(&mut self) -> HookBuilder<'_, D, E>
pub fn hook<E: Endpoint<D>>(&mut self) -> HookBuilder<'_, D, E>
Hooks around endpoint E, for every caller: app.hook::<SignUpEmail>().before(..).
Sourcepub fn sign_in_gate<F, Fut>(&mut self, gate: F) -> &mut Self
pub fn sign_in_gate<F, Fut>(&mut self, gate: F) -> &mut Self
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.
Sourcepub fn session_gate<F, Fut>(&mut self, gate: F) -> &mut Self
pub fn session_gate<F, Fut>(&mut self, gate: F) -> &mut Self
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.
Sourcepub fn fixed_session_expiry(
&mut self,
fixed: impl Fn(&SessionView) -> bool + Send + Sync + 'static,
) -> &mut Self
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.
Sourcepub fn session_resolver(
&mut self,
resolver: impl SessionResolver<D>,
) -> &mut Self
pub fn session_resolver( &mut self, resolver: impl SessionResolver<D>, ) -> &mut Self
Turns non-cookie credentials (bearer tokens, API keys) into a session.
Sourcepub fn on_response(
&mut self,
hook: impl Fn(&Ctx<D>, &mut Response) + Send + Sync + 'static,
) -> &mut Self
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.
Sourcepub fn on_session_created<F, Fut>(&mut self, hook: F) -> &mut Self
pub fn on_session_created<F, Fut>(&mut self, hook: F) -> &mut Self
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.
Sourcepub fn on<Ev, F, Fut>(&mut self, handler: F) -> &mut Self
pub fn on<Ev, F, Fut>(&mut self, handler: F) -> &mut Self
Runs after any endpoint that emitted Ev succeeds. Errors are logged, not returned.
Sourcepub fn rate_limit(
&mut self,
pattern: impl Into<String>,
limit: Limit,
) -> &mut Self
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.
Sourcepub fn errors<E: ErrorCodes>(&mut self) -> &mut Self
pub fn errors<E: ErrorCodes>(&mut self) -> &mut Self
Registers error codes so two plugins can’t claim the same one.