Compare commits

..

No commits in common. "4274fdaf939ab2181b556fe169cd51b7b485b765" and "c25cf96015b0dfa6e315150b8c5525b6c4397819" have entirely different histories.

9 changed files with 27 additions and 71 deletions

View File

@ -23,11 +23,8 @@ futures-util = "0.3"
num_cpus = "1.15"
bcrypt = "0.14"
uuid = { version = "1.3", features = ["v4", "serde"] }
oauth2 = { version = "4.3", optional = true }
reqwest = { version = "0.11", features = ["json"], optional = true }
[features]
gitea = ["oauth2", "reqwest"]
oauth2 = "4.3"
reqwest = { version = "0.11", features = ["json"] }
[dev-dependencies]
actix-rt = "2.8"

View File

@ -1,12 +1,8 @@
#[cfg(feature = "gitea")]
use oauth2::{basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl};
use serde::{Deserialize, Serialize};
use std::env;
#[cfg(feature = "gitea")]
use oauth2::{basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl};
/// Gitea OAuth configuration
#[cfg(feature = "gitea")]
#[derive(Clone, Debug)]
pub struct GiteaOAuthConfig {
/// OAuth client
@ -15,7 +11,6 @@ pub struct GiteaOAuthConfig {
pub instance_url: String,
}
#[cfg(feature = "gitea")]
impl GiteaOAuthConfig {
/// Creates a new Gitea OAuth configuration
pub fn new() -> Self {
@ -53,7 +48,6 @@ impl GiteaOAuthConfig {
}
/// Gitea user information structure
#[cfg(feature = "gitea")]
#[derive(Debug, Deserialize, Serialize)]
pub struct GiteaUser {
/// User ID

View File

@ -1,21 +1,15 @@
use actix_web::{web, HttpRequest, HttpResponse, Responder, Result, http::header, cookie::Cookie};
use actix_session::Session;
use oauth2::{AuthorizationCode, CsrfToken, Scope, TokenResponse};
use reqwest::Client;
use crate::config::oauth::GiteaOAuthConfig;
use crate::models::user::{User, UserRole};
use crate::controllers::auth::AuthController;
#[cfg(feature = "gitea")]
use oauth2::{AuthorizationCode, CsrfToken, Scope, TokenResponse};
#[cfg(feature = "gitea")]
use reqwest::Client;
#[cfg(feature = "gitea")]
use crate::config::oauth::GiteaOAuthConfig;
/// Controller for handling Gitea authentication
#[cfg(feature = "gitea")]
pub struct GiteaAuthController;
#[cfg(feature = "gitea")]
impl GiteaAuthController {
/// Initiate the OAuth flow
pub async fn login(
@ -213,7 +207,6 @@ impl GiteaAuthController {
}
/// Query parameters for the OAuth callback
#[cfg(feature = "gitea")]
#[derive(serde::Deserialize)]
pub struct CallbackQuery {
pub code: String,

View File

@ -1,6 +1,5 @@
// Export controllers
pub mod auth;
pub mod debug;
#[cfg(feature = "gitea")]
pub mod gitea_auth;
pub mod home;

View File

@ -1,8 +1,6 @@
#[cfg(feature = "gitea")]
use crate::config::oauth::GiteaOAuthConfig;
use crate::controllers::auth::AuthController;
use crate::controllers::debug::DebugController;
#[cfg(feature = "gitea")]
use crate::controllers::gitea_auth::GiteaAuthController;
use crate::controllers::home::HomeController;
use crate::middleware::JwtAuth;
@ -12,6 +10,9 @@ use actix_web::web;
/// Configures all application routes
pub fn configure_routes(cfg: &mut web::ServiceConfig) {
// Create the OAuth configuration
let oauth_config = web::Data::new(GiteaOAuthConfig::new());
// Configure session middleware with the consistent key
let session_middleware =
SessionMiddleware::builder(CookieSessionStore::default(), SESSION_KEY.clone())
@ -26,35 +27,29 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) {
)
.build();
let mut scope = web::scope("")
.wrap(session_middleware)
// Home routes
.route("/", web::get().to(HomeController::index))
.route("/about", web::get().to(HomeController::about))
// Auth routes
.route("/login", web::get().to(AuthController::login_page))
.route("/login", web::post().to(AuthController::login))
.route("/register", web::get().to(AuthController::register_page))
.route("/register", web::post().to(AuthController::register))
.route("/logout", web::get().to(AuthController::logout))
// Debug routes
.route("/debug", web::get().to(DebugController::debug_info));
#[cfg(feature = "gitea")]
{
// Create the OAuth configuration
let oauth_config = web::Data::new(GiteaOAuthConfig::new());
// Gitea OAuth configuration and routes
scope = scope
// Public routes that don't require authentication
cfg.service(
web::scope("")
.wrap(session_middleware)
.app_data(oauth_config.clone())
// Home routes
.route("/", web::get().to(HomeController::index))
.route("/about", web::get().to(HomeController::about))
// Auth routes
.route("/login", web::get().to(AuthController::login_page))
.route("/login", web::post().to(AuthController::login))
.route("/register", web::get().to(AuthController::register_page))
.route("/register", web::post().to(AuthController::register))
.route("/logout", web::get().to(AuthController::logout))
// Gitea OAuth routes
.route("/auth/gitea", web::get().to(GiteaAuthController::login))
.route(
"/auth/gitea/callback",
web::get().to(GiteaAuthController::callback),
);
}
cfg.service(scope);
)
// Debug routes
.route("/debug", web::get().to(DebugController::debug_info)),
);
// Protected routes that require authentication
cfg.service(

View File

@ -25,7 +25,6 @@
<hr>
{% if gitea_enabled %}
<div class="text-center">
<p>Or login with:</p>
<a href="/auth/gitea" class="btn btn-secondary">
@ -34,7 +33,6 @@
Login with Gitea
</a>
</div>
{% endif %}
<hr>

View File

@ -34,7 +34,6 @@
<hr>
{% if gitea_enabled %}
<div class="text-center">
<p>Or register with:</p>
<a href="/auth/gitea" class="btn btn-secondary">
@ -43,7 +42,6 @@
Register with Gitea
</a>
</div>
{% endif %}
<hr>

View File

@ -1,8 +0,0 @@
#!/bin/bash
# Get the directory of the script and change to it
cd "$(dirname "$0")"
export SECRET_KEY=1234
cargo run

View File

@ -1,10 +0,0 @@
#!/bin/bash
# Get the directory of the script and change to it
cd "$(dirname "$0")"
export GITEA_CLIENT_ID="your_client_id"
export GITEA_CLIENT_SECRET="your_client_secret"
export GITEA_INSTANCE_URL="https://gitea.example.com"
export APP_URL="http://localhost:9999"
cargo run --features gitea