Expand description
Authentication/security extension points.
Ports shared by application code and the HTTP host:
ITokenIssuer— mint a token fromTokenClaims(login).ISessionStore— revoke / query revoked tokens (logout, forced sign-out); the authentication middleware consults it after verifying a token.IPasswordHasher— hash/verify passwords as PHC strings (Argon2id by default).
Two dependency-free primitives for the security-adjacent code every application writes at least once:
constant_time_eq— compare secrets without leaking where they differ.OneTimeSecret— a TTL-bound secret consumed exactly once (installation token, invite link, password reset), with aOneTimeSecretStatefor telling 401 from 410.
§How the framework uses these ports
The ports exist so business crates write “call the port” code, never crypto or session-plumbing code:
- Login — a handler injects
Arc<dyn ITokenIssuer>, callsITokenIssuer::issue, and returnsIssuedToken::token. The password is checked withArc<dyn IPasswordHasher>(hashon registration,verifyon login,needs_rehashto upgrade old hashes). - Authenticated requests — the authentication middleware verifies the
token, then (when an
ISessionStoreis registered) asksISessionStore::is_revokedabout the token’sjti; revoked → 401. - Logout — the handler calls
ISessionStore::revokewith thejtiit stored (or received) at login; no wait forexpis needed.
The traits are dependency-free so they can be implemented anywhere; the
implementations that need third-party crates live in rust-webx-host
(JwtTokenIssuer, Argon2PasswordHasher), while the ones that need nothing
live here (InMemorySessionStore).
Structs§
- InMemory
Session Store - Process-local
ISessionStore— the dependency-free default. - Issued
Token - A token minted by an
ITokenIssuer. - OneTime
Secret - A TTL-bound secret that can be consumed at most once.
- Token
Claims - Claims a caller hands to an
ITokenIssuer.
Enums§
- OneTime
Secret State - Lifecycle of a
OneTimeSecretslot.
Traits§
- IPassword
Hasher - Hash and verify passwords (Argon2id by default).
- ISession
Store - Revocation state for issued tokens.
- IToken
Issuer - Mint a token from
TokenClaims.
Functions§
- constant_
time_ eq - Compare two byte slices without returning early on a difference.