auth: Allow HTTP basic auth for users This can be used soon to push data as a user from the terminal where the cookie isn't set like in the browser.
Dependencies
- [2]
JJQ4LMUMdependecy: Remove future No longer required, so cleaning it up right now. - [3]
SZIYDOFDrefactor: Move User guard to the model The User model didn't have the FromRequest 'constructor' for the guard. This felt off. Now some Request knowledge leaks to the model, but still it seems better. - [4]
KFVJ3KMWfrontend: Introduce navigation bar Minor changes to the front-end mostly, to allow users to register, sign in, and sign out. The sign out route is changed to a GET endpoint, as links in HTML cannot DELETE. - [5]
5UNA2DEAroutes: Register and authenticate users Allow users to sign up, and sign in/sign out. The routes are added, though the design of the pages is very bare bones still, it's hard to go through the full flow to demo. On the server side: Passwords are stored encrypted in the database with salts. This uses the PG encrypt tooling to prevent against bugs and maintainance costs on this project. When a user is signed in, the user ID is set in a private cookie. Rocket has Guards for routes, which has not been implemented yet for this project. - [6]
Z63HIZPStesting: Move tests to specific directory Tests I didn't really write until today, as I mostly didn't really know how to set it up. This is now partially mitigated, just by forcing myself to do it. There's a few problems still in the code; the database is shared with the dev application for instance. Though as a start I'll take it. - [7]
FS2NWBVNpijul: Start of push/pull work This change includes one API endpoint, .pijul. It allows for getting a channels remote ID. A lot of plumbing around repositories is added too, from init to opening pristine and actions like it. - [8]
K4JNAJOFdatabase: Connect to postgres on Rocket boot As database I've chosen PostgreSQL, as my personal experience has been good with it. This change allows Rocket to connect to the database on booting the server. It depends on the DATABASE_URL being set, and for now circumvents the Rocket config helpers as it seemed faster to be up and running this way. - [9]
W3M3C7CCInitial commit This change includes a very small hello world application server written in Rust using Rocket.rs. Managing dependencies is done with Nix as that works well between Linux and Mac for me. - [*]
TWIZ7QV4db: Add interface to add a project Right now a project has a name, and an owner which is hardcoded to 1. This is because basically I'm speedrunning to implement push/pull of Pijul and then revisit to add depth to features and tests. Model code is now split into files properly too.
Change contents
- edit in tests/controller_test.rs at line 1
mod common; - replacement in tests/controller_test.rs at line 6
use rocket::local::asynchronous::Client;let client = Client::tracked(nidobyte::rocket()).await.expect("foo");let client = common::testing_client().await; - edit in src/models/users.rs at line 73
if let Some(user) = user_from_basic_auth(db, &*request).await {return Outcome::Success(user);}// Try getting the user from the cookie - edit in src/models/users.rs at line 92
async fn user_from_basic_auth(db: &State<Database>, req: &Request<'_>) -> Option<User> {use rocket_basicauth::BasicAuth;info!("trying basic auth");let credentials = match BasicAuth::from_request(req).await {Outcome::Success(ba) => ba,_ => return None,};info!("extracted basic auth");match User::authenticate(db, credentials.username, credentials.password).await {Ok(some) => some,_ => None,}} - replacement in src/lib.rs at line 10
mod database;pub mod database; - replacement in src/lib.rs at line 14
mod models;pub mod models; - replacement in src/database/mod.rs at line 8
pub(crate) type Database = sqlx::PgPool;pub type Database = sqlx::PgPool; - edit in Cargo.toml at line 17
rocket-basicauth = "2.1"http-auth-basic = "0.3.1" # Only used for testing at this time - edit in Cargo.lock at line 197
version = "0.12.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"[[package]]name = "base64" - replacement in Cargo.lock at line 420
"base64","base64 0.13.0", - edit in Cargo.lock at line 1125
][[package]]name = "http-auth-basic"version = "0.3.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "c692c953703936fa684b33084ce21ad4248769b5052079bbd89afe6b354a5762"dependencies = ["base64 0.12.3", - edit in Cargo.lock at line 1581[4.14495][11.4612]
"http-auth-basic", - edit in Cargo.lock at line 1586
"rocket-basicauth", - replacement in Cargo.lock at line 1891
"base64","base64 0.13.0", - edit in Cargo.lock at line 2188
][[package]]name = "rocket-basicauth"version = "2.1.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "79128c0f55b7bc6785c13816d71af4baee156bd615b09468800edaaa7da56a08"dependencies = ["base64 0.13.0","log","rocket", - replacement in Cargo.lock at line 2309
"base64","base64 0.13.0", - replacement in Cargo.lock at line 2605
"base64","base64 0.13.0",