Skip to content

Plugins

Every auth feature in authx-rs is a plugin — a struct that wraps a storage adapter and an event bus, and exposes a focused API.

pub struct EmailPasswordService<S> {
storage: S,
events: EventBus,
session_ttl_secs: i64,
lockout: Option<(LoginAttemptTracker, LockoutConfig)>,
}
impl<S> EmailPasswordService<S>
where
S: UserRepository + SessionRepository + CredentialRepository
+ Clone + Send + Sync + 'static,
{
pub fn new(storage: S, events: EventBus, session_ttl_secs: i64) -> Self { … }
pub async fn sign_up(&self, email: &str, password: &str) -> Result<User> { … }
pub async fn sign_in(&self, email: &str, password: &str, ip: &str) -> Result<AuthResponse> { … }
pub async fn sign_out(&self, raw_token: &str) -> Result<()> { … }
}
  1. Plugins own no state beyond storage + events. All persistence goes through the repository layer.
  2. Plugins emit events — they never write audit logs directly. AuditLogger subscribes to the event bus and handles persistence.
  3. Plugins enforce business rules (weak password, duplicate email, lockout) — storage handles persistence.
  4. No plugin depends on another plugin. EmailPasswordService doesn’t import AdminService. Cross-cutting concerns use the shared repository layer.
PluginServiceKey methods
Email/PasswordEmailPasswordServicesign_up, sign_in, sign_out, sign_out_all
Magic LinkMagicLinkServicerequest_link, verify
Email OTPEmailOtpServiceissue, verify
TOTPTotpServicebegin_setup, confirm_setup, verify, disable
Password ResetPasswordResetServicerequest_reset, reset_password
Email VerificationEmailVerificationServiceissue, verify
OAuth (Social)OAuthServicebegin, callback
API KeysApiKeyServicecreate, list, revoke, authenticate
Username LoginUsernameServicesign_up, sign_in
Anonymous AuthAnonymousServicecreate_guest, upgrade
OrganizationOrgServicecreate, invite_member, accept_invite, switch_org
AdminAdminServiceban_user, unban_user, impersonate, list_users