about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2021-12-06 20:39:04 +0300
committerVika <vika@fireburn.ru>2021-12-06 20:42:50 +0300
commit9a9776230ce8d12d305ca8db19cc76f20ae40926 (patch)
tree26d1e166ae68825e55084b43c52afcb446521b11 /src/lib.rs
parent913779655c1feddc55d37bebbdd7df87eb7c9c0f (diff)
Added support for IndieAuth client sign in
This will allow readers to view private posts intended just for them.

Additionally fixed bugs in patterns due to which webmentions might not
have been sent.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs20
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))