Update config and dependencies for auth
Refactor configuration loading to separate user credentials from server settings. Update dependencies to their latest compatible versions to leverage new features and security patches. Key changes include: - Moving user credentials (`api_key`, `web_password`, `role`) from `.env` to a dedicated `users.toml` file for better manageability and security. - Introducing an `AuthenticatedUser` struct and extractor for API key-based authentication. - Updating `axum` and related crates to leverage Rust edition 2024 improvements. - Adjusting configuration values and tests to reflect these changes.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
use axum::Json;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::auth::AuthenticatedUser;
|
||||
use crate::error::AppError;
|
||||
|
||||
pub async fn handle_whoami(user: AuthenticatedUser) -> Result<Json<Value>, AppError> {
|
||||
Ok(Json(json!({
|
||||
"slug": user.slug,
|
||||
"role": user.role,
|
||||
"data_dir": user.data_dir.to_string_lossy(),
|
||||
})))
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
mod debug;
|
||||
mod health;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::routing::get;
|
||||
use axum::Router;
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
pub fn api_router() -> Router<Arc<Config>> {
|
||||
Router::new().route("/api/health", axum::routing::get(health::handle_health))
|
||||
Router::new()
|
||||
.route("/api/health", get(health::handle_health))
|
||||
.route("/api/debug/whoami", get(debug::handle_whoami))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user