diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs index 817bda7..eb915c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,7 @@ where authorization_endpoint: surf::Url, media_endpoint: Option<String>, internal_token: Option<String>, + cookie_secret: String, http_client: surf::Client, storage: StorageBackend, } @@ -48,6 +49,13 @@ where .with(frontend::ErrorHandlerMiddleware {}) .get(frontend::mainpage) .post(frontend::onboarding_receiver); + app.at("/login") + .with(frontend::ErrorHandlerMiddleware {}) + .get(frontend::login::form) + .post(frontend::login::handler); + app.at("/login/callback") + .with(frontend::ErrorHandlerMiddleware {}) + .get(frontend::login::callback); app.at("/static/*path") .with(frontend::ErrorHandlerMiddleware {}) .get(frontend::handle_static); @@ -64,7 +72,14 @@ where app.at("/metrics").get(metrics::gather); app.with(metrics::InstrumentationMiddleware {}); - + app.with( + tide::sessions::SessionMiddleware::new( + tide::sessions::CookieStore::new(), + &app.state().cookie_secret.as_bytes() + ) + .with_cookie_name("kittybox_session") + .without_save_unchanged() + ); app } @@ -93,6 +108,7 @@ pub async fn get_app_with_file( authorization_endpoint: surf::Url, backend_uri: String, media_endpoint: Option<String>, + cookie_secret: String, internal_token: Option<String>, ) -> App<database::FileStorage> { let folder = backend_uri.strip_prefix("file://").unwrap(); @@ -102,6 +118,7 @@ pub async fn get_app_with_file( media_endpoint, authorization_endpoint, internal_token, + cookie_secret, storage: database::FileStorage::new(path).await.unwrap(), http_client: surf::Client::new(), }); @@ -128,6 +145,7 @@ pub async fn get_app_with_test_file( authorization_endpoint: Url::parse("https://indieauth.com/auth").unwrap(), storage: backend.clone(), internal_token: None, + cookie_secret: "1234567890abcdefghijklmnopqrstuvwxyz".to_string(), http_client: surf::Client::new(), }); (tempdir, backend, equip_app(app)) |