Expand description
Framework-agnostic authentication engine for axum + sqlx fullstack apps.
arium owns the auth domain — password hashing, sessions, OAuth and
OpenID Connect (GitHub, Google, Microsoft, or any OIDC issuer), MFA/TOTP,
email verification + password reset, RBAC, API tokens, and an audit log —
plus the install helper that bolts the whole thing onto an
axum::Router. It has no UI-framework dependency; framework adapters such
as arium-dioxus wrap these primitives in their own server fns + UI.
Typical server-side usage:
use arium::{
AuthConfig, Mailer, install, migrator,
oauth::{github::GithubProvider, OAuthRegistry},
};
let pool = sqlx::sqlite::SqlitePoolOptions::new()
.connect_with("sqlite://./app.db?mode=rwc".parse()?)
.await?;
migrator().run(&pool).await?;
let mut oauth = OAuthRegistry::new(pool.clone())?;
if let Some(gh) = GithubProvider::from_env()? {
oauth = oauth.with_provider(gh);
}
let cfg = AuthConfig::builder(pool.clone(), Mailer::from_env()?)
.oauth(oauth)
.build()?;
// `router` is any `axum::Router` (e.g. your framework's server router).
let router = install(router, cfg).await?;oauth-github is on by default. The opt-in oauth-oidc, oauth-google,
and oauth-microsoft features add a generic OpenID Connect provider plus
Google/Microsoft presets — each from_env()-constructed and registered the
same way as GithubProvider above.
§Per-resource authorization
Beyond global RBAC (flat permission tokens), the authz module adds
relationship-based checks — “what role does this user hold on this
resource?” Implement authz::ResourceAuthority over your own membership
storage and guard resource-scoped mutations with require_resource; it
does a fresh per-request lookup and default-denies. arium ships no
membership table — the app owns that storage; arium owns the enforcement
boundary and the ResourceRole lattice.
Re-exports§
pub use config::AuditConfig;pub use config::AuthConfig;pub use config::AuthConfigBuilder;pub use config::RECOMMENDED_HSTS;pub use config::RateLimitConfig;pub use api_key::ApiKeyUser;pub use extract::AuditCtx;pub use extract::AuthUser;pub use extract::AuthzCtx;pub use extract::ResourceAuthorityExt;pub use extract::SessionStore;pub use mail::Mailer;pub use arium_wire as wire;
Modules§
- api_key
- Bearer-token authentication: the axum middleware that turns an
Authorization: Bearer <token>header into anapi_key::ApiKeyUserrequest extension, applied automatically byinstall. Gated ontokens(it hashes the presented token withauth::tokens). Bearer-token authentication middleware. - auth
- Server-side authentication primitives: the
Usermodel that the session layer loads, the password and MFA flows, the audit-log emitter, and the helpers every server fn uses to identify the caller. - authz
- Per-resource authorization, re-exported from the standalone
arium_authzcrate soarium::authz::*andarium::membership::*keep resolving for existing code (and the framework adapters). The global↔resource bridge (require_resource_or_permission) and the bundledSqlMembershipStorestay in this crate — they touch the auth engine and its schema. Per-resource, relationship-based authorization — the second axis arium’s global RBAC (flat permission tokens) can’t express. - config
- Configuration object the consumer hands to
crate::install. - extract
- Axum request extractors shared across arium’s framework adapters.
- Outbound email infrastructure.
- membership
- Per-resource authorization, re-exported from the standalone
arium_authzcrate soarium::authz::*andarium::membership::*keep resolving for existing code (and the framework adapters). The global↔resource bridge (require_resource_or_permission) and the bundledSqlMembershipStorestay in this crate — they touch the auth engine and its schema. Membership lifecycle and enumeration — the management layer aboveauthz’s per-request enforcement. - oauth
- Pluggable third-party OAuth providers.
- pool
- Compile-time-selected sqlx pool aliases.
Structs§
- ApiToken
View - One row in the user’s API-token list. The full secret is NEVER returned
after creation — only
prefix("dxsk_abcd") so the UI can disambiguate tokens by sight. - Create
ApiToken Response - Response from
create_api_token.tokenis the cleartext secret — shown to the user ONCE and never recoverable from the server. - Membership
- One user’s role on a resource, as returned by
MembershipStore::list_members. - MfaSetup
View - Setup payload returned to the client when starting MFA enrollment.
recovery_codesis the only time these appear in plaintext anywhere — the server only persists Argon2 hashes. - Provider
Info - One third-party identity provider the server has credentials for and is
willing to mount routes for. Returned by
available_providersso the client can render a button per entry without needing to know which provider features were compiled in. - Resource
Ref - Identifies one resource instance for an authorization check.
kindis an opaque, app-chosen namespace ("board","doc", …) andidthe row id within it. Borrowed so a check on the request hot path needn’t allocate. - SqlMembership
Store - A
MembershipStorebacked by arium’sarium_resource_memberstable. Stateless — construct withSqlMembershipStorewherever a store is needed. - TxExec
- A live transaction handle arium opens and threads into
MembershipStorewrite primitives so a composite’s steps commit or roll back together. - User
Profile - Profile fields safe to expose to the client.
Enums§
- Login
Outcome - Result of a sign-in or sign-up attempt.
- Membership
Error - Why a membership composite did not complete.
- MfaStatus
View - Whether the current user has MFA enabled, pending, or off entirely.
- Resource
Authz Error - Why a
require_resourcecheck did not pass. - Resource
Grant - Which axis authorized a
require_resource_or_permissioncall. - Resource
Role - The relationship role a user holds on a single resource (a board, a
document, …). The variants form an ordered lattice: a higher role
subsumes every capability of the lower ones, so the access check is a plain
held_role >= required_role. Declaration order defines that ordering via the derivedOrd— do not reorder the variants.
Traits§
- Membership
Store - Storage-shaped primitives for managing and enumerating resource memberships.
- Resource
Authority - App-implemented lookup of a user’s role on a resource — the one method an app writes to plug its own membership storage into arium’s per-resource enforcement. arium never stores resource memberships itself.
Functions§
- grant_
membership - Grant
target_idthe roleroleonresource, acting asactor_id. - install
- Attach all arium wiring to
routerand return the augmented Router. - membership_
migrator - Returns the migrator that creates the
arium_resource_memberstable backing the bundledSqlMembershipStore. - migrator
- Returns the embedded migrator that creates the
users,oauth_accounts,roles,audit_events,api_keys, and related tables arium owns. - require_
resource - Fresh, per-request authorization check for a single resource — the security boundary for resource-scoped actions.
- require_
resource_ audited require_resourceplus the standard audit-on-denial, driven by an already-resolveduser_id. The reusable kernel behind the framework adapters’ session guards (e.g. dioxus’srequire_resource_dioxus).- require_
resource_ or_ permission - Authorize on either axis: a sufficient per-resource role, or a global permission token. The one place the two authorization stories compose.
- revoke_
membership - Remove
user_id’s membership ofresource, refusing if they are the soleResourceRole::Owner(MembershipError::LastOwner). - transfer_
ownership - Transfer ownership of
resourcefromfrom_idtoto_id: the new owner is promoted toResourceRole::Ownerand the previous owner demoted toResourceRole::Manager, atomically.from_idmust currently be anOwner(MembershipError::NotOwnerotherwise).
Type Aliases§
- Shared
Resource Authority - Cheaply-cloneable shared handle to the app’s
ResourceAuthority. Apps register this as anaxum::Extension(directly, or via arium’sAuthConfigBuilder::resource_authority); server fns reach it through thearium::extract::ResourceAuthorityExtextractor.