Expand description
§rainier-auth
Authentication and authorization: Guards that say who is making a
request, and a Gate that says whether they may.
Authenticatable | what the framework needs to know about a user model |
UserProvider / RepositoryUserProvider | how users are found and their credentials verified |
Hasher / Argon2Hasher | password hashing |
Guard / TokenGuard / SessionGuard | how a request is tied to a user |
AuthManager | named guards — auth:api |
Authenticate | the middleware that enforces it |
Gate | abilities and policies |
ⓘ
let provider = Arc::new(RepositoryUserProvider::new(users, hasher));
let auth = Arc::new(
AuthManager::<User>::new("web")
.register(Arc::new(SessionGuard::new("web", provider.clone(), sessions)))
.register(Arc::new(TokenGuard::new("api", provider))),
);
middleware.alias_factory("auth", move |args| {
Ok(Arc::new(Authenticate::from_args(auth.clone(), args)) as Arc<_>)
});
router.get("/me", show).middleware(["auth:api"]);§One user type per manager
AuthManager is generic over the user model rather than yielding
dyn Authenticatable. An application has one user model and wants it back
with its own type; erasing it would only force a downcast at every call
site. An application with genuinely distinct user kinds — customers and
staff, in different tables — registers one manager each, which is clearer
than one registry returning different shapes.
Re-exports§
pub use abilities::Abilities;pub use challenge::Challenges;pub use confirm::confirm_password;pub use confirm::ConfirmPassword;pub use gate::Actor;pub use gate::Gate;pub use guard::AuthManager;pub use guard::Guard;pub use guard::GuardExt;pub use guard::SessionGuard;pub use guard::StatefulGuard;pub use guard::TokenGuard;pub use hashing::Argon2Hasher;pub use hashing::Hasher;pub use legacy::LegacyVerifier;pub use middleware::AbilitiesRequestExt;pub use middleware::Authenticate;pub use middleware::AuthenticatedUser;pub use middleware::RedirectIfAuthenticated;pub use middleware::RequireAbility;pub use middleware::TokenAbilities;pub use session::AUTH_KEY;pub use user::Authenticatable;pub use user::Credentials;pub use user::RepositoryUserProvider;pub use user::UserProvider;
Modules§
- abilities
- What an issued token is allowed to do —
Abilities. - challenge
- Short-lived, single-use, attempt-limited codes —
Challenges. - confirm
- Re-asking for the password before something serious —
ConfirmPassword. - gate
- Authorization — the
Gateand its abilities. - guard
- Guards —
Guard,TokenGuard,SessionGuardandAuthManager. - hashing
- Password hashing — the
Hasherport and its Argon2 implementation. - legacy
- Verifying hashes this application did not write —
LegacyVerifier. - middleware
- The
Authenticatemiddleware —->middleware("auth"). - session
- The session, as authentication sees it.
- user
- Who can log in —
Authenticatable,CredentialsandUserProvider.
Structs§
- Memory
Session Store - Sessions held in this process’s memory.
- Session
- A request’s session.
Traits§
- Session
Store - Where session data is kept between requests.
Functions§
- generate_
session_ id - Generate a session id: 256 bits of randomness, hex-encoded.