From 746fb68684f3228022042f647134748f770dcc34 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 28 May 2023 15:34:36 +0200 Subject: [PATCH] feat: with persistent session state Signed-off-by: kjuulh --- Cargo.lock | 798 ++++++++++++++---- Cargo.toml | 20 +- como_api/Cargo.toml | 1 + como_api/src/controllers/auth.rs | 11 +- como_api/src/router.rs | 9 +- como_bin/src/main.rs | 2 +- como_infrastructure/Cargo.toml | 40 +- como_infrastructure/src/register.rs | 10 +- .../src/services/item_service.rs | 2 +- 9 files changed, 661 insertions(+), 232 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9662dc6..804ab56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -171,7 +171,18 @@ checksum = "db4ce4441f99dbd377ca8a8f57b698c44d0d6e712d8329b5040da5a64aa1ce73" dependencies = [ "base64ct", "blake2", - "password-hash", + "password-hash 0.4.2", +] + +[[package]] +name = "argon2" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95c2fcf79ad1932ac6269a738109997a83c227c09b75842ae564dc8ede6a861c" +dependencies = [ + "base64ct", + "blake2", + "password-hash 0.5.0", ] [[package]] @@ -192,6 +203,17 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71938f30533e4d95a6d17aa530939da3842c2ab6f4f84b9dae68447e4129f74a" +[[package]] +name = "async-channel" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + [[package]] name = "async-compression" version = "0.3.15" @@ -207,35 +229,32 @@ dependencies = [ ] [[package]] -name = "async-graphql" -version = "4.0.16" +name = "async-executor" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9ed522678d412d77effe47b3c82314ac36952a35e6e852093dd48287c421f80" +checksum = "6fa3dc5f2a8564f07759c008b9109dc0d39de92a88d5588b8a5036d286383afb" dependencies = [ - "async-graphql-derive 4.0.16", - "async-graphql-parser 4.0.16", - "async-graphql-value 4.0.16", - "async-stream", - "async-trait", - "base64 0.13.1", - "bytes", - "fast_chemail", - "fnv", - "futures-util", - "http", - "indexmap", - "mime", - "multer", - "num-traits", + "async-lock", + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1b6f5d7df27bd294849f8eec66ecfc63d11814df7a4f5d74168a2394467b776" +dependencies = [ + "async-channel", + "async-executor", + "async-io", + "async-lock", + "blocking", + "futures-lite", "once_cell", - "pin-project-lite", - "regex", - "serde", - "serde_json", - "serde_urlencoded", - "static_assertions", - "tempfile", - "thiserror", ] [[package]] @@ -244,9 +263,9 @@ version = "5.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "364423936c4b828ac1615ce325e528c5afbe6e6995d799ee5683c7d36720dfa4" dependencies = [ - "async-graphql-derive 5.0.9", - "async-graphql-parser 5.0.9", - "async-graphql-value 5.0.9", + "async-graphql-derive", + "async-graphql-parser", + "async-graphql-value", "async-stream", "async-trait", "base64 0.13.1", @@ -278,9 +297,9 @@ version = "5.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f05d3a107ce33726d3bdb3fc5d760c84fc2b2f29db18f359a2f05d1efa3a7ac4" dependencies = [ - "async-graphql 5.0.9", + "async-graphql", "async-trait", - "axum 0.6.18", + "axum", "bytes", "futures-util", "http-body", @@ -289,22 +308,6 @@ dependencies = [ "tower-service", ] -[[package]] -name = "async-graphql-derive" -version = "4.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c121a894495d7d3fc3d4e15e0a9843e422e4d1d9e3c514d8062a1c94b35b005d" -dependencies = [ - "Inflector", - "async-graphql-parser 4.0.16", - "darling 0.14.4", - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 1.0.109", - "thiserror", -] - [[package]] name = "async-graphql-derive" version = "5.0.9" @@ -312,7 +315,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23a06320343bbe0a1f2e29ec6d1ed34e0460f10e6827b3154a78e4ccc039dbc4" dependencies = [ "Inflector", - "async-graphql-parser 5.0.9", + "async-graphql-parser", "darling 0.14.4", "proc-macro-crate", "proc-macro2", @@ -321,42 +324,18 @@ dependencies = [ "thiserror", ] -[[package]] -name = "async-graphql-parser" -version = "4.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b6c386f398145c6180206c1869c2279f5a3d45db5be4e0266148c6ac5c6ad68" -dependencies = [ - "async-graphql-value 4.0.16", - "pest", - "serde", - "serde_json", -] - [[package]] name = "async-graphql-parser" version = "5.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46ce3b4b57e2a4630ea5e69eeb02fb5ee3c5f48754fcf7fd6a7bf3b4f96538f0" dependencies = [ - "async-graphql-value 5.0.9", + "async-graphql-value", "pest", "serde", "serde_json", ] -[[package]] -name = "async-graphql-value" -version = "4.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a941b499fead4a3fb5392cabf42446566d18c86313f69f2deab69560394d65f" -dependencies = [ - "bytes", - "indexmap", - "serde", - "serde_json", -] - [[package]] name = "async-graphql-value" version = "5.0.9" @@ -369,6 +348,26 @@ dependencies = [ "serde_json", ] +[[package]] +name = "async-io" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +dependencies = [ + "async-lock", + "autocfg", + "cfg-if 1.0.0", + "concurrent-queue", + "futures-lite", + "log", + "parking", + "polling", + "rustix", + "slab", + "socket2", + "waker-fn", +] + [[package]] name = "async-lock" version = "2.7.0" @@ -378,6 +377,36 @@ dependencies = [ "event-listener", ] +[[package]] +name = "async-native-tls" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e9e7a929bd34c68a82d58a4de7f86fffdaf97fb2af850162a7bb19dd7269b33" +dependencies = [ + "async-std", + "native-tls", + "thiserror", + "url", +] + +[[package]] +name = "async-process" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a9d28b1d97e08915212e2e45310d47854eafa69600756fc735fb788f75199c9" +dependencies = [ + "async-io", + "async-lock", + "autocfg", + "blocking", + "cfg-if 1.0.0", + "event-listener", + "futures-lite", + "rustix", + "signal-hook", + "windows-sys 0.48.0", +] + [[package]] name = "async-session" version = "3.0.0" @@ -399,6 +428,43 @@ dependencies = [ "sha2 0.9.9", ] +[[package]] +name = "async-sqlx-session" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0ee17fe642044cab8b0b11d07dae6e9cb7114e5e61b7cb4a322c603e7ed961a" +dependencies = [ + "async-session", + "sqlx 0.5.13", +] + +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-channel", + "async-global-executor", + "async-io", + "async-lock", + "async-process", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -421,6 +487,12 @@ dependencies = [ "syn 2.0.18", ] +[[package]] +name = "async-task" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" + [[package]] name = "async-trait" version = "0.1.68" @@ -432,6 +504,15 @@ dependencies = [ "syn 2.0.18", ] +[[package]] +name = "atoi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616896e05fc0e2649463a93a15183c6a16bf03413a7af88ef1285ddedfa9cda5" +dependencies = [ + "num-traits", +] + [[package]] name = "atoi" version = "1.0.0" @@ -441,43 +522,18 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atomic-waker" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" + [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "axum" -version = "0.5.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" -dependencies = [ - "async-trait", - "axum-core 0.2.9", - "bitflags", - "bytes", - "futures-util", - "http", - "http-body", - "hyper", - "itoa", - "matchit 0.5.0", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper", - "tokio", - "tower", - "tower-http 0.3.5", - "tower-layer", - "tower-service", -] - [[package]] name = "axum" version = "0.6.18" @@ -485,7 +541,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8175979259124331c1d7bf6586ee7e0da434155e4b2d48ec2c8386281d8df39" dependencies = [ "async-trait", - "axum-core 0.3.4", + "axum-core", "axum-macros", "base64 0.21.2", "bitflags", @@ -496,7 +552,7 @@ dependencies = [ "http-body", "hyper", "itoa", - "matchit 0.7.0", + "matchit", "memchr", "mime", "percent-encoding", @@ -515,22 +571,6 @@ dependencies = [ "tower-service", ] -[[package]] -name = "axum-core" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e5939e02c56fecd5c017c37df4238c0a839fa76b7f97acdd7efb804fd181cc" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http", - "http-body", - "mime", - "tower-layer", - "tower-service", -] - [[package]] name = "axum-core" version = "0.3.4" @@ -554,8 +594,8 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "febf23ab04509bd7672e6abe76bd8277af31b679e89fa5ffc6087dc289a448a3" dependencies = [ - "axum 0.6.18", - "axum-core 0.3.4", + "axum", + "axum-core", "bytes", "cookie 0.17.0", "futures-util", @@ -590,7 +630,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "714cad544cd87d8da821cda715bb9aaa5d4d1adbdb64c549b18138e3cbf93c44" dependencies = [ "async-session", - "axum 0.6.18", + "axum", "axum-extra", "futures", "http-body", @@ -695,6 +735,21 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blocking" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77231a1c8f801696fc0123ec6150ce92cffb8e164a02afb9c8ddee0e9b65ad65" +dependencies = [ + "async-channel", + "async-lock", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", + "log", +] + [[package]] name = "brotli" version = "3.3.4" @@ -831,9 +886,10 @@ name = "como_api" version = "0.1.0" dependencies = [ "anyhow", - "async-graphql 5.0.9", + "async-graphql", "async-graphql-axum", - "axum 0.6.18", + "async-sqlx-session", + "axum", "axum-extra", "axum-sessions", "como_core", @@ -845,7 +901,7 @@ dependencies = [ "openidconnect", "serde", "serde_json", - "sqlx", + "sqlx 0.6.3", "tokio", "tower", "tower-http 0.4.0", @@ -859,7 +915,7 @@ name = "como_bin" version = "0.1.0" dependencies = [ "anyhow", - "axum 0.6.18", + "axum", "clap", "como_api", "como_core", @@ -887,7 +943,7 @@ name = "como_domain" version = "0.1.0" dependencies = [ "anyhow", - "async-graphql 5.0.9", + "async-graphql", "serde", "serde_json", "uuid", @@ -898,10 +954,10 @@ name = "como_gql" version = "0.1.0" dependencies = [ "anyhow", - "argon2", - "async-graphql 5.0.9", + "argon2 0.4.1", + "async-graphql", "async-graphql-axum", - "axum 0.6.18", + "axum", "axum-extra", "axum-sessions", "como_core", @@ -912,7 +968,7 @@ dependencies = [ "rand_core", "serde", "serde_json", - "sqlx", + "sqlx 0.6.3", "tokio", "tower-http 0.3.5", "tracing", @@ -925,28 +981,29 @@ name = "como_infrastructure" version = "0.1.0" dependencies = [ "anyhow", - "argon2", - "async-graphql 4.0.16", - "async-graphql-axum", - "axum 0.5.17", - "axum-extra", - "axum-sessions", + "argon2 0.5.0", + "async-sqlx-session", + "async-trait", + "axum", "clap", "como_core", "como_domain", - "cookie 0.16.2", - "dotenv", "rand_core", - "serde", - "serde_json", - "sqlx", + "sqlx 0.6.3", "tokio", - "tower-http 0.3.5", "tracing", - "tracing-subscriber", "uuid", ] +[[package]] +name = "concurrent-queue" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "const-oid" version = "0.9.2" @@ -994,6 +1051,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -1009,15 +1076,30 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49fc9a695bca7f35f5f4c15cddc84415f66a74ea78eef08e90c5024f2b540e23" +dependencies = [ + "crc-catalog 1.1.1", +] + [[package]] name = "crc" version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" dependencies = [ - "crc-catalog", + "crc-catalog 2.2.0", ] +[[package]] +name = "crc-catalog" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccaeedb56da03b09f598226e25e80088cb4cd25f316e6e4df7d695f0feeb1403" + [[package]] name = "crc-catalog" version = "2.2.0" @@ -1087,9 +1169,9 @@ dependencies = [ [[package]] name = "crypto-mac" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25fab6889090c8133f3deb8f73ba3c65a7f456f66436fc012a1b1e272b1e103e" +checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" dependencies = [ "generic-array", "subtle", @@ -1379,6 +1461,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.1.0" @@ -1447,6 +1544,21 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "futures-macro" version = "0.3.28" @@ -1521,6 +1633,18 @@ dependencies = [ "polyval", ] +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "group" version = "0.12.1" @@ -1565,6 +1689,15 @@ dependencies = [ "thiserror", ] +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash 0.7.6", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -1580,6 +1713,15 @@ dependencies = [ "ahash 0.8.3", ] +[[package]] +name = "hashlink" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" +dependencies = [ + "hashbrown 0.11.2", +] + [[package]] name = "hashlink" version = "0.8.2" @@ -1659,7 +1801,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" dependencies = [ - "crypto-mac 0.11.0", + "crypto-mac 0.11.1", "digest 0.9.0", ] @@ -1893,6 +2035,15 @@ dependencies = [ "simple_asn1", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1932,11 +2083,11 @@ dependencies = [ [[package]] name = "log" -version = "0.4.17" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" dependencies = [ - "cfg-if 1.0.0", + "value-bag", ] [[package]] @@ -1948,12 +2099,6 @@ dependencies = [ "regex-automata", ] -[[package]] -name = "matchit" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" - [[package]] name = "matchit" version = "0.7.0" @@ -2008,14 +2153,13 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +checksum = "eebffdb73fe72e917997fad08bdbf31ac50b0fa91cec93e69a0662e4264d454c" dependencies = [ "libc", - "log", "wasi", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -2042,6 +2186,24 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "nom" version = "7.1.3" @@ -2165,9 +2327,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openidconnect" -version = "3.0.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91f944611b8e7e8e4bb7e3c95a98f2b8d1aba56cfa6af00f31d9b0f7829d8431" +checksum = "6d88a00e70c6e920d4c781285b74c558f2939a24a0ae662c60d9ae189724b557" dependencies = [ "base64 0.13.1", "chrono", @@ -2194,6 +2356,50 @@ dependencies = [ "url", ] +[[package]] +name = "openssl" +version = "0.10.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01b8574602df80f7b85fdfc5392fa884a4e3b3f4f35402c070ab34c3d3f78d56" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e17f59264b2809d77ae94f0e1ebabc434773f370d6ca667bd223ea10e06cc7e" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "ordered-float" version = "2.10.0" @@ -2231,6 +2437,12 @@ dependencies = [ "sha2 0.10.6", ] +[[package]] +name = "parking" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" + [[package]] name = "parking_lot" version = "0.11.2" @@ -2290,6 +2502,17 @@ dependencies = [ "subtle", ] +[[package]] +name = "password-hash" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + [[package]] name = "paste" version = "1.0.12" @@ -2428,6 +2651,28 @@ dependencies = [ "spki", ] +[[package]] +name = "pkg-config" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" + +[[package]] +name = "polling" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags", + "cfg-if 1.0.0", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.48.0", +] + [[package]] name = "polyval" version = "0.6.0" @@ -2784,6 +3029,15 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +[[package]] +name = "schannel" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +dependencies = [ + "windows-sys 0.42.0", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -2814,6 +3068,29 @@ dependencies = [ "zeroize", ] +[[package]] +name = "security-framework" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f51d0c0d83bec45f16480d0ce0058397a69e48fcdc52d1dc8855fb68acbd31a7" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.163" @@ -2907,6 +3184,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "sha-1" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.7", +] + [[package]] name = "sha1" version = "0.10.5" @@ -2951,6 +3239,16 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "signal-hook" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" +dependencies = [ + "libc", + "signal-hook-registry", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -3029,6 +3327,17 @@ dependencies = [ "der", ] +[[package]] +name = "sqlformat" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4b7922be017ee70900be125523f38bdd644f4f06a1b16e8fa5a8ee8c34bffd4" +dependencies = [ + "itertools", + "nom", + "unicode_categories", +] + [[package]] name = "sqlformat" version = "0.2.1" @@ -3040,14 +3349,73 @@ dependencies = [ "unicode_categories", ] +[[package]] +name = "sqlx" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "551873805652ba0d912fec5bbb0f8b4cdd96baf8e2ebf5970e5671092966019b" +dependencies = [ + "sqlx-core 0.5.13", + "sqlx-macros 0.5.13", +] + [[package]] name = "sqlx" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8de3b03a925878ed54a954f621e64bf55a3c1bd29652d0d1a17830405350188" dependencies = [ - "sqlx-core", - "sqlx-macros", + "sqlx-core 0.6.3", + "sqlx-macros 0.6.3", +] + +[[package]] +name = "sqlx-core" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48c61941ccf5ddcada342cd59e3e5173b007c509e1e8e990dafc830294d9dc5" +dependencies = [ + "ahash 0.7.6", + "atoi 0.4.0", + "base64 0.13.1", + "bitflags", + "byteorder", + "bytes", + "chrono", + "crc 2.1.0", + "crossbeam-queue", + "dirs", + "either", + "event-listener", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-util", + "hashlink 0.7.0", + "hex", + "hkdf", + "hmac 0.12.1", + "indexmap", + "itoa", + "libc", + "log", + "md-5", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "rand", + "serde", + "serde_json", + "sha-1", + "sha2 0.10.6", + "smallvec", + "sqlformat 0.1.8", + "sqlx-rt 0.5.13", + "stringprep", + "thiserror", + "url", + "whoami", ] [[package]] @@ -3057,12 +3425,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa8241483a83a3f33aa5fff7e7d9def398ff9990b2752b6c6112b83c6d246029" dependencies = [ "ahash 0.7.6", - "atoi", + "atoi 1.0.0", "base64 0.13.1", "bitflags", "byteorder", "bytes", - "crc", + "crc 3.0.1", "crossbeam-queue", "dirs", "dotenvy", @@ -3072,7 +3440,7 @@ dependencies = [ "futures-core", "futures-intrusive", "futures-util", - "hashlink", + "hashlink 0.8.2", "hex", "hkdf", "hmac 0.12.1", @@ -3093,8 +3461,8 @@ dependencies = [ "sha1", "sha2 0.10.6", "smallvec", - "sqlformat", - "sqlx-rt", + "sqlformat 0.2.1", + "sqlx-rt 0.6.3", "stringprep", "thiserror", "tokio-stream", @@ -3104,6 +3472,26 @@ dependencies = [ "whoami", ] +[[package]] +name = "sqlx-macros" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc0fba2b0cae21fc00fe6046f8baa4c7fcb49e379f0f592b04696607f69ed2e1" +dependencies = [ + "dotenv", + "either", + "heck", + "once_cell", + "proc-macro2", + "quote", + "serde_json", + "sha2 0.10.6", + "sqlx-core 0.5.13", + "sqlx-rt 0.5.13", + "syn 1.0.109", + "url", +] + [[package]] name = "sqlx-macros" version = "0.6.3" @@ -3120,12 +3508,23 @@ dependencies = [ "serde", "serde_json", "sha2 0.10.6", - "sqlx-core", - "sqlx-rt", + "sqlx-core 0.6.3", + "sqlx-rt 0.6.3", "syn 1.0.109", "url", ] +[[package]] +name = "sqlx-rt" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4db708cd3e459078f85f39f96a00960bd841f66ee2a669e90bf36907f5a79aae" +dependencies = [ + "async-native-tls", + "async-std", + "native-tls", +] + [[package]] name = "sqlx-rt" version = "0.6.3" @@ -3161,9 +3560,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "subtle" -version = "2.5.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" @@ -3280,9 +3679,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.28.1" +version = "1.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aa32867d44e6f2ce3385e89dceb990188b8bb0fb25b0cf576647a6f98ac5105" +checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2" dependencies = [ "autocfg", "bytes", @@ -3673,12 +4072,30 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4d330786735ea358f3bc09eea4caa098569c1c93f342d9aca0514915022fe7e" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + [[package]] name = "want" version = "0.3.0" @@ -3842,6 +4259,21 @@ dependencies = [ "windows-targets 0.48.0", ] +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-sys" version = "0.45.0" @@ -4000,11 +4432,11 @@ checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" [[package]] name = "zitadel" -version = "3.3.1" +version = "3.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43fe41f6acca0776f1233361164b4629a0db3176e9e031f0cc7665da8338789a" +checksum = "f663404099529f467b6ee708371187191bd0ab94d4821ea2357a3fe74ce2b4c8" dependencies = [ - "axum 0.6.18", + "axum", "axum-extra", "base64-compat", "custom_error", diff --git a/Cargo.toml b/Cargo.toml index c722cc4..5be0b67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,13 +21,14 @@ async-graphql = { version = "5.0.9", features = ["uuid"] } async-graphql-axum = "5.0.9" axum = { version = "0.6.18", features = ["headers", "macros"] } -axum-extra = { version = "*", features = ["cookie", "cookie-private"] } -axum-sessions = { version = "*" } +axum-extra = { version = "0.7.4", features = ["cookie", "cookie-private"] } +axum-sessions = { version = "0.5.0" } +async-sqlx-session = { version = "0.4.0", features = ["pg"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.68" -sqlx = { version = "0.6", features = [ +sqlx = { version = "0.6.2", features = [ "runtime-tokio-rustls", "postgres", "migrate", @@ -35,11 +36,14 @@ sqlx = { version = "0.6", features = [ "offline", ] } -tokio = { version = "1.20.1", features = ["full"] } +tokio = { version = "1.28.2", features = ["full"] } -uuid = { version = "1.1.2", features = ["v4", "fast-rng", "serde"] } -anyhow = "1.0.60" +uuid = { version = "1.3.3", features = ["v4", "fast-rng", "serde"] } +anyhow = "1.0.71" dotenv = "0.15.0" -tracing = "0.1.36" -tracing-subscriber = { version = "0.3.15", features = ["env-filter"] } +tracing = "0.1.37" +tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } clap = { version = "4.3.0", features = ["derive", "env"] } + +argon2 = { version = "0.5.0" } +rand_core = { version = "0.6.4" } diff --git a/como_api/Cargo.toml b/como_api/Cargo.toml index 1bd7d96..f076fb5 100644 --- a/como_api/Cargo.toml +++ b/como_api/Cargo.toml @@ -24,6 +24,7 @@ sqlx.workspace = true anyhow.workspace = true dotenv.workspace = true tracing.workspace = true +async-sqlx-session.workspace = true zitadel = { version = "3.3.1", features = ["axum"] } tower = "0.4.13" diff --git a/como_api/src/controllers/auth.rs b/como_api/src/controllers/auth.rs index 6e4be06..662d7af 100644 --- a/como_api/src/controllers/auth.rs +++ b/como_api/src/controllers/auth.rs @@ -1,6 +1,7 @@ use crate::router::AppState; use crate::zitadel::{IntrospectionConfig, IntrospectionState}; +use async_sqlx_session::PostgresSessionStore; use axum::extract::{FromRef, FromRequestParts, Query, State}; use axum::headers::Cookie; use axum::http::request::Parts; @@ -9,7 +10,7 @@ use axum::http::{header::SET_COOKIE, HeaderMap}; use axum::response::{IntoResponse, Redirect}; use axum::routing::get; use axum::{async_trait, RequestPartsExt, Router, TypedHeader}; -use axum_sessions::async_session::{MemoryStore, Session, SessionStore}; +use axum_sessions::async_session::{Session, SessionStore}; use como_domain::users::User; use como_infrastructure::register::ServiceRegister; use oauth2::basic::BasicClient; @@ -39,7 +40,7 @@ pub struct AuthRequest { pub async fn login_authorized( Query(query): Query, - State(store): State, + State(store): State, State(oauth_client): State, State(introspection_state): State, ) -> impl IntoResponse { @@ -99,13 +100,13 @@ pub struct UserFromSession {} #[async_trait] impl FromRequestParts for UserFromSession where - MemoryStore: FromRef, + PostgresSessionStore: FromRef, S: Send + Sync, { type Rejection = (StatusCode, &'static str); async fn from_request_parts(parts: &mut Parts, state: &S) -> Result { - let store = MemoryStore::from_ref(state); + let store = PostgresSessionStore::from_ref(state); let cookie: Option> = parts.extract().await.unwrap(); @@ -116,7 +117,7 @@ where let session_cookie = session_cookie.unwrap(); - tracing::info!( + tracing::debug!( "UserFromSession: got session cookie from user agent, {}={}", COOKIE_NAME, session_cookie diff --git a/como_api/src/router.rs b/como_api/src/router.rs index f379b5f..b66a6d5 100644 --- a/como_api/src/router.rs +++ b/como_api/src/router.rs @@ -1,10 +1,10 @@ use std::env; use anyhow::Context; +use async_sqlx_session::PostgresSessionStore; use axum::extract::FromRef; use axum::http::{HeaderValue, Method}; use axum::Router; -use axum_sessions::async_session::MemoryStore; use como_infrastructure::register::ServiceRegister; use oauth2::basic::BasicClient; use tower::ServiceBuilder; @@ -32,11 +32,10 @@ impl Api { .build() .await?; - let store = MemoryStore::new(); let oauth_client = oauth_client(); let app_state = AppState { oauth_client, - store, + store: service_register.session_store.clone(), introspection_state: is, }; @@ -81,7 +80,7 @@ impl Api { pub struct AppState { oauth_client: BasicClient, introspection_state: IntrospectionState, - store: MemoryStore, + store: PostgresSessionStore, } impl FromRef for BasicClient { @@ -90,7 +89,7 @@ impl FromRef for BasicClient { } } -impl FromRef for MemoryStore { +impl FromRef for PostgresSessionStore { fn from_ref(state: &AppState) -> Self { state.store.clone() } diff --git a/como_bin/src/main.rs b/como_bin/src/main.rs index a3739d6..469932a 100644 --- a/como_bin/src/main.rs +++ b/como_bin/src/main.rs @@ -27,7 +27,7 @@ async fn main() -> anyhow::Result<()> { let pool = ConnectionPoolManager::new_pool(&config.database_url, true).await?; - let service_register = ServiceRegister::new(pool, config.clone()); + let service_register = ServiceRegister::new(pool, config.clone()).await?; Api::new( config.api_port, diff --git a/como_infrastructure/Cargo.toml b/como_infrastructure/Cargo.toml index c8e57ae..1aedaa9 100644 --- a/como_infrastructure/Cargo.toml +++ b/como_infrastructure/Cargo.toml @@ -6,32 +6,20 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -como_core = { path = "../como_core" } -como_domain = { path = "../como_domain" } +como_core.workspace = true +como_domain.workspace = true -async-graphql = "4.0.6" -async-graphql-axum = "*" -axum = "0.5.13" -axum-extra = { version = "*", features = ["cookie", "cookie-private"] } -axum-sessions = { version = "*" } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0.68" -tokio = { version = "1.20.1", features = ["full"] } -uuid = { version = "1.1.2", features = ["v4", "fast-rng"] } -sqlx = { version = "0.6", features = [ - "runtime-tokio-rustls", - "postgres", - "migrate", - "uuid", - "offline", -] } -anyhow = "1.0.60" -dotenv = "0.15.0" -tracing = "0.1.36" -tracing-subscriber = { version = "0.3.15", features = ["env-filter"] } -tower-http = { version = "0.3.4", features = ["full"] } -argon2 = "0.4" -rand_core = { version = "0.6", features = ["std"] } -cookie = { version = "0.16", features = ["secure", "percent-encode"] } +axum.workspace = true +async-trait.workspace = true +uuid.workspace = true +anyhow.workspace = true +sqlx.workspace = true + +async-sqlx-session.workspace = true + +tokio.workspace = true clap.workspace = true +tracing.workspace = true +argon2.workspace = true +rand_core.workspace = true diff --git a/como_infrastructure/src/register.rs b/como_infrastructure/src/register.rs index bce20aa..2196379 100644 --- a/como_infrastructure/src/register.rs +++ b/como_infrastructure/src/register.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use async_sqlx_session::PostgresSessionStore; use como_core::{items::DynItemService, projects::DynProjectService, users::DynUserService}; use tracing::log::info; @@ -17,22 +18,25 @@ pub struct ServiceRegister { pub item_service: DynItemService, pub project_service: DynProjectService, pub user_service: DynUserService, + pub session_store: PostgresSessionStore, } impl ServiceRegister { - pub fn new(pool: ConnectionPool, _config: Arc) -> Self { + pub async fn new(pool: ConnectionPool, config: Arc) -> anyhow::Result { info!("creating services"); let item_service = Arc::new(MemoryItemService::new()) as DynItemService; let project_service = Arc::new(MemoryProjectService::new()) as DynProjectService; let user_service = Arc::new(DefaultUserService::new(pool.clone())) as DynUserService; + let store = PostgresSessionStore::new(&config.database_url).await?; info!("services created succesfully"); - return Self { + Ok(Self { item_service, user_service, project_service, - }; + session_store: store, + }) } } diff --git a/como_infrastructure/src/services/item_service.rs b/como_infrastructure/src/services/item_service.rs index c5faf65..1b2f5a0 100644 --- a/como_infrastructure/src/services/item_service.rs +++ b/como_infrastructure/src/services/item_service.rs @@ -3,7 +3,7 @@ use std::{ sync::{Arc, Mutex}, }; -use axum::async_trait; +use async_trait::async_trait; use como_core::items::ItemService; use como_domain::item::{ queries::{GetItemQuery, GetItemsQuery},