feat: setup github provider with generic trait, proper routes, session & jwt handling, errors & user agent

This commit is contained in:
Ryan Walters
2025-09-17 03:32:32 -05:00
parent 264478bdaa
commit f3db44c48b
12 changed files with 604 additions and 20 deletions
+20 -5
View File
@@ -1,23 +1,38 @@
use axum::Router;
use axum::{routing::get, Router};
use axum_cookie::CookieLayer;
use crate::config::Config;
use crate::{app::AppState, auth::AuthRegistry, config::Config};
mod routes;
mod app;
mod auth;
mod config;
mod errors;
mod session;
#[tokio::main]
async fn main() {
// Load environment variables
#[cfg(debug_assertions)]
dotenvy::from_path(format!("{}.env", env!("CARGO_MANIFEST_DIR"))).ok();
dotenvy::from_path(std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(".env")).ok();
#[cfg(not(debug_assertions))]
dotenvy::dotenv().ok();
// Load configuration
let config: Config = config::load_config();
let app = Router::new().fallback(|| async { "Hello, World!" });
let addr = std::net::SocketAddr::new(config.host, config.port);
let auth = AuthRegistry::new(&config).expect("auth initializer");
let app = Router::new()
.route("/", get(|| async { "Hello, World! Visit /auth/github to start OAuth flow." }))
.route("/auth/{provider}", get(routes::oauth_authorize_handler))
.route("/auth/{provider}/callback", get(routes::oauth_callback_handler))
.route("/logout", get(routes::logout_handler))
.route("/profile", get(routes::profile_handler))
.with_state(AppState::new(config, auth))
.layer(CookieLayer::default());
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
}