| Crates.io | dusk-auth-core-rust |
| lib.rs | dusk-auth-core-rust |
| version | 0.1.0 |
| created_at | 2026-01-13 15:24:53.251372+00 |
| updated_at | 2026-01-13 15:24:53.251372+00 |
| description | An opinionated, framework-agnostic authentication core enforcing correct session-based auth practices |
| homepage | |
| repository | https://github.com/dusk-lab/dusk-auth-core-rust.git |
| max_upload_size | |
| id | 2040443 |
| size | 38,678 |
A synchronous, framework-agnostic authentication core that enforces correct session-based auth practices.
Design Philosophy • Core Invariants • How to Use • Architecture
Modern authentication systems often suffer from a token-first mindset: JWTs are treated as sessions, refresh tokens never rotate, and logout is reduced to deleting client-side state.
These approaches are convenient—but dangerous.
dusk-auth-core-rust takes the opposite approach.
It is a pure domain engine that enforces authentication correctness through explicit session state and non-negotiable invariants. It does not handle HTTP, async IO, JWT encoding, or databases. Instead, it provides a strict and test-proven core that other layers must respect.
This crate is intentionally:
Common authentication failures include:
JWTs as Sessions Stateless tokens treated as the source of truth, making revocation impossible.
Zombie Logouts “Logout” that only clears cookies while server-side state remains valid.
Infinite Refresh Tokens Long-lived refresh tokens that never rotate, enabling permanent access if stolen.
Boolean Auth
Reducing authentication to true / false, hiding critical distinctions like expired vs revoked.
dusk-auth-core-rust encodes the correct model directly into code.
If a mistake is common, this library makes it hard—or impossible—to implement.
This library is not a toolkit. It is a system with enforced rules.
Tokens are derived proofs, not the source of truth.
Refresh tokens are single-use credentials.
Logout is a server-side state transition.
Authentication never returns a boolean.
Validation produces a typed decision:
ValidExpiredRevokedInvalidThis forces correct handling and meaningful security responses.
Sessions are mortal.
No session lives forever.
dusk-auth-core-rust is used inside your application, not as a standalone service.
You choose how sessions are persisted by implementing SessionStore.
let store = InMemorySessionStore::new();
let auth = Authenticator::new(store);
(In production, this would be backed by a database or Redis.)
At request boundaries, validate tokens and session state together.
let decision = auth.validate_access_token(&access_token, now);
match decision {
AuthDecision::Valid(session) => {
// Safe to proceed
}
AuthDecision::Expired => {
// Client may attempt refresh
}
AuthDecision::Revoked => {
// Security event: token was valid but session was killed
}
AuthDecision::Invalid => {
// Malformed or unknown token
}
}
Refresh enforces rotation and reuse detection.
let (new_access, new_refresh) =
auth.refresh_session(&refresh_token, now)?;
If a refresh token is reused:
RefreshTokenReused error is returnedLogout is explicit and destructive.
auth.revoke_session(&session_id);
After this:
RevokedThis crate is the core, not the whole system.
Those concerns belong in adapter crates built on top of this core.
Typical layering:
dusk-auth-core-rust ← this crate (rules & invariants)
dusk-auth-adapter-* ← HTTP / async / framework glue
application code ← routing, storage, identity
Current Version: v1.0 (core complete)
The core authentication engine is complete and fully covered by invariant tests. Future work will focus on adapters and integrations, not changes to the core logic.
Licensed under the MIT License.
Contributions are welcome only if they preserve the core invariants.