Skip to main content

Crate rainier_auth

Crate rainier_auth 

Source
Expand description

§rainier-auth

Authentication and authorization: Guards that say who is making a request, and a Gate that says whether they may.

Authenticatablewhat the framework needs to know about a user model
UserProvider / RepositoryUserProviderhow users are found and their credentials verified
Hasher / Argon2Hasherpassword hashing
Guard / TokenGuard / SessionGuardhow a request is tied to a user
AuthManagernamed guards — auth:api
Authenticatethe middleware that enforces it
Gateabilities 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 Gate and its abilities.
guard
Guards — Guard, TokenGuard, SessionGuard and AuthManager.
hashing
Password hashing — the Hasher port and its Argon2 implementation.
legacy
Verifying hashes this application did not write — LegacyVerifier.
middleware
The Authenticate middleware — ->middleware("auth").
session
The session, as authentication sees it.
user
Who can log in — Authenticatable, Credentials and UserProvider.

Structs§

MemorySessionStore
Sessions held in this process’s memory.
Session
A request’s session.

Traits§

SessionStore
Where session data is kept between requests.

Functions§

generate_session_id
Generate a session id: 256 bits of randomness, hex-encoded.

Attribute Macros§

async_trait