Microservice to bring 2FA to self hosted PDSes

Added rng code and place holder for db call. wont build

Changed files
+20 -7
migrations_bells_and_whistles
src
xrpc
+2
Cargo.lock
··· 1652 1652 name = "pds_gatekeeper" 1653 1653 version = "0.1.0" 1654 1654 dependencies = [ 1655 + "anyhow", 1655 1656 "axum", 1656 1657 "axum-template", 1657 1658 "dotenvy", ··· 1660 1661 "hyper-util", 1661 1662 "jwt-compact", 1662 1663 "lettre", 1664 + "rand 0.9.2", 1663 1665 "rust-embed", 1664 1666 "scrypt", 1665 1667 "serde",
+2
Cargo.toml
··· 22 22 handlebars = { version = "6.3.2", features = ["rust-embed"] } 23 23 rust-embed = "8.7.2" 24 24 axum-template = { version = "3.0.0", features = ["handlebars"] } 25 + rand = "0.9.2" 26 + anyhow = "1.0.99"
-3
migrations_bells_and_whistles/.keep
··· 1 - # This directory holds SQLx migrations for the bells_and_whistles.sqlite database. 2 - # It is intentionally empty for now; running `sqlx::migrate!` will still ensure the 3 - # migrations table exists and succeed with zero migrations.
+16 -4
src/xrpc/helpers.rs
··· 1 + use crate::AppState; 1 2 use axum::body::{Body, to_bytes}; 2 3 use axum::extract::Request; 3 - use axum::http::{HeaderMap, Method, StatusCode, Uri}; 4 4 use axum::http::header::CONTENT_TYPE; 5 + use axum::http::{HeaderMap, Method, StatusCode, Uri}; 5 6 use axum::response::{IntoResponse, Response}; 7 + use rand::distr::{Alphanumeric, SampleString}; 6 8 use serde::de::DeserializeOwned; 9 + use sqlx::SqlitePool; 10 + use sqlx::sqlite::SqliteError; 7 11 use tracing::error; 8 - 9 - use crate::AppState; 10 12 11 13 /// The result of a proxied call that attempts to parse JSON. 12 14 pub enum ProxiedResult<T> { ··· 125 127 } 126 128 } 127 129 128 - 129 130 /// Build a JSON error response with the required Content-Type header 130 131 /// Content-Type: application/json;charset=utf-8 131 132 /// Body shape: { "error": string, "message": string } ··· 148 149 .body(Body::from(body_str)) 149 150 .map_err(|_| StatusCode::BAD_REQUEST) 150 151 } 152 + 153 + pub fn get_random_token() -> String { 154 + let full_code = Alphanumeric.sample_string(&mut rand::rng(), 10); 155 + //The PDS implementation creates in lowercase, then converts to uppercase. 156 + //Just going a head and doing uppercase here. 157 + let slice_one = &full_code[0..5].to_ascii_uppercase(); 158 + let slice_two = &full_code[5..10].to_ascii_uppercase(); 159 + format!("{}-{}", slice_one, slice_two) 160 + } 161 + 162 + pub fn create_two_factor_token(account_db: &SqlitePool, did: String) -> anyhow::Result<String> {}