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_claim<F>(&mut self, cleanup: F) -> &mut Self
pub fn on_claim<F>(&mut self, cleanup: F) -> &mut Self
Removes this plugin’s credentials and pending state of a user that proof of the email
claims (Internal::claim_user): anything the previous holder of the address could
sign in or finish a sign-in with, such as passkeys, API keys or a two-factor enrollment.
Runs inside the claim’s transaction, after core deleted the user’s accounts and
sessions; query through Claim::db. An error rolls the claim back and fails the
request, so the claim never commits with a cleanup missing.
app.on_claim(|claim| {
Box::pin(async move {
claim.db().delete::<ApiKey>(ApiKey::USER_ID.eq(claim.user_id())).await?;
Ok(())
})
});Sourcepub fn prepare_user_input<F, Fut>(&mut self, hook: F) -> &mut Self
pub fn prepare_user_input<F, Fut>(&mut self, hook: F) -> &mut Self
Checks and rewrites the app and plugin columns a client sends for a user (the extra
camelCase keys of a sign-up, update-user or email-code sign-up body) before they are
parsed, on every route that writes them: Internal::user_fields. In registration
order; an error refuses the request. For plugins whose columns have rules, such as a
username that must be valid, normalized and free.
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 account_provider(&mut self, provider_id: impl Into<String>) -> &mut Self
pub fn account_provider(&mut self, provider_id: impl Into<String>) -> &mut Self
Declares that this plugin writes account rows with provider_id (a social
provider’s id). With Builder::only_owned_accounts
on, fastauth touches only rows of credential and of the providers plugins declare.
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.