Move session middleware outside such that we can access webdav endpoints from the frontend

This commit is contained in:
Lennart
2025-06-09 17:29:33 +02:00
parent 2ba0beeafc
commit 9dd5995950
4 changed files with 39 additions and 59 deletions

View File

@@ -14,10 +14,6 @@ use rustical_store::{
auth::{AuthenticationProvider, middleware::AuthenticationLayer},
};
use std::sync::Arc;
use tower_sessions::{
Expiry, SessionManagerLayer, SessionStore,
cookie::{SameSite, time::Duration},
};
use url::Url;
mod assets;
@@ -45,19 +41,13 @@ use crate::{
},
};
pub fn frontend_router<
AP: AuthenticationProvider,
CS: CalendarStore,
AS: AddressbookStore,
S: SessionStore + Clone,
>(
pub fn frontend_router<AP: AuthenticationProvider, CS: CalendarStore, AS: AddressbookStore>(
prefix: &'static str,
auth_provider: Arc<AP>,
cal_store: Arc<CS>,
addr_store: Arc<AS>,
frontend_config: FrontendConfig,
oidc_config: Option<OidcConfig>,
session_store: S,
) -> Router {
let mut router = Router::new();
router = router
@@ -123,12 +113,6 @@ pub fn frontend_router<
router = router
.layer(AuthenticationLayer::new(auth_provider.clone()))
.layer(
SessionManagerLayer::new(session_store)
.with_secure(true)
.with_same_site(SameSite::Strict)
.with_expiry(Expiry::OnInactivity(Duration::hours(2))),
)
.layer(Extension(auth_provider.clone()))
.layer(Extension(cal_store.clone()))
.layer(Extension(addr_store.clone()))

View File

@@ -1,3 +1,4 @@
use crate::unauthorized_handler;
use axum::routing::{get, post};
use axum::{Extension, Router, middleware};
use chrono::{DateTime, Utc};
@@ -8,11 +9,6 @@ use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
use tower_sessions::cookie::SameSite;
use tower_sessions::cookie::time::Duration;
use tower_sessions::{Expiry, SessionManagerLayer, SessionStore};
use crate::unauthorized_handler;
mod routes;
#[derive(Debug, Clone)]
@@ -50,10 +46,9 @@ pub struct NextcloudFlows {
flows: RwLock<HashMap<String, NextcloudFlow>>,
}
pub fn nextcloud_login_router<AP: AuthenticationProvider, S: SessionStore + Clone>(
pub fn nextcloud_login_router<AP: AuthenticationProvider>(
nextcloud_flows_state: Arc<NextcloudFlows>,
auth_provider: Arc<AP>,
session_store: S,
) -> Router {
Router::new()
.route("/poll/{flow}", post(post_nextcloud_poll::<AP>))
@@ -65,11 +60,5 @@ pub fn nextcloud_login_router<AP: AuthenticationProvider, S: SessionStore + Clon
.layer(Extension(nextcloud_flows_state))
.layer(Extension(auth_provider.clone()))
.layer(AuthenticationLayer::new(auth_provider.clone()))
.layer(
SessionManagerLayer::new(session_store)
.with_secure(true)
.with_same_site(SameSite::Strict)
.with_expiry(Expiry::OnInactivity(Duration::hours(2))),
)
.layer(middleware::from_fn(unauthorized_handler))
}