Skip to main content

Crate modo_auth

Crate modo_auth 

Source
Expand description

Session-based authentication and Argon2id password hashing for modo applications.

§Overview

modo-auth provides three building blocks:

An optional templates feature adds UserContextLayer, a Tower middleware that injects the authenticated user into the minijinja template context under the key "user".

§Quick start

use modo_auth::{UserProvider, UserProviderService, Auth, PasswordHasher, PasswordConfig};

struct UserRepo { /* db pool */ }

impl UserProvider for UserRepo {
    type User = MyUser;

    async fn find_by_id(&self, id: &str) -> Result<Option<MyUser>, modo::Error> {
        // load from DB
        todo!()
    }
}

#[modo::main]
async fn main(app: modo::app::AppBuilder, config: Config) -> Result<(), Box<dyn std::error::Error>> {
    let repo = UserRepo { /* ... */ };
    let hasher = PasswordHasher::default();

    app.service(UserProviderService::new(repo))
       .service(hasher)
       .run()
       .await
}

Re-exports§

pub use extractor::Auth;
pub use extractor::OptionalAuth;
pub use password::PasswordConfig;
pub use password::PasswordHasher;
pub use provider::UserProvider;
pub use provider::UserProviderService;

Modules§

extractor
password
provider