User identification, authentication, and authorization for Axum.
User identification, authentication, and authorization for Axum.
axum-login
User identification, authentication, and authorization for Axum.This crate provides user identification, authentication, and authorization
as a tower middleware for axum.
It offers:
AuthSession to easily manage authentication and authorization. This is
also an extractor, so it can be used directly in your axum handlers.AuthUser and AuthnBackend, allowing for any user
type and any user management backend. Your database? Yep. LDAP? Sure. An
auth provider? You bet.AuthzBackend trait, which allows applications to define custom
permissions. Both user and group permissions are supported.login_required and permission_required
macros, and via the require builder (require-builder feature). The
builder is the long-term primary surface; macros are convenience wrappers
over the same behavior.tower-sessions
for high-performing and ergonomic session management. Look ma, no deadlocks!To use the crate in your project, add the following to your Cargo.toml file:
[dependencies]
axum-login = "0.18.0"We recommend reviewing our sqlite example. There is also a template for cargo-generate using postgres.
[!NOTE] See the crate documentation for usage information.
…You can customize access logic with .decision(...), which receives an
AuthSession plus Arc when you build with shared state.
The middleware surfaces follow the same contract:
500 Internal Server Error.require-builder: Enables the builder-based require module, which is the primary middleware surface.macros-middleware: Enables the login_required! and permission_required! macros. These are convenience wrappers over the builder and are enabled by default.Example (builder only, no macros):
[dependencies]
axum-login = { version = "0.18.0", default-features = false, features = ["require-builder"] }This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.
We've put together a number of examples to help get you started. You're also welcome to open a discussion and ask additional questions you might have.
We appreciate all kinds of contributions, thank you!
No open issues yet, or sync has not completed.