diff --git a/server/Cargo.lock b/server/Cargo.lock index f43dbd72..3dd73cef 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -17,6 +17,34 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -41,6 +69,18 @@ dependencies = [ "backtrace", ] +[[package]] +name = "argon2" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072" +dependencies = [ + "base64ct", + "blake2", + "cpufeatures", + "password-hash", +] + [[package]] name = "async-trait" version = "0.1.78" @@ -49,7 +89,16 @@ checksum = "461abc97219de0eaaf81fe3ef974a540158f3d079c2ab200f891f1a2ef201e85" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.53", +] + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", ] [[package]] @@ -69,10 +118,10 @@ dependencies = [ "axum-macros", "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.0", "http-body-util", - "hyper", + "hyper 1.2.0", "hyper-util", "itoa", "matchit", @@ -102,8 +151,8 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.0", "http-body-util", "mime", "pin-project-lite", @@ -114,6 +163,26 @@ dependencies = [ "tracing", ] +[[package]] +name = "axum-login" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f1d7775e438e00a773a3f3651cc46bdb7877a0b22e590289c0f8b5ed92f8f95" +dependencies = [ + "async-trait", + "axum", + "form_urlencoded", + "ring", + "serde", + "thiserror", + "tower-cookies", + "tower-layer", + "tower-service", + "tower-sessions", + "tracing", + "urlencoding", +] + [[package]] name = "axum-macros" version = "0.4.1" @@ -123,7 +192,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.53", ] [[package]] @@ -141,12 +210,30 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64" version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "bitflags" version = "1.3.2" @@ -162,6 +249,15 @@ dependencies = [ "serde", ] +[[package]] +name = "blake2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +dependencies = [ + "digest", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -177,6 +273,12 @@ version = "3.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.5.0" @@ -257,6 +359,12 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "const-random" version = "0.1.18" @@ -286,6 +394,27 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "cookie" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cd91cf61412820176e137621345ee43b3f4423e589e7ae4e50d601d93e35ef8" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -301,6 +430,36 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crossbeam-queue" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + [[package]] name = "crunchy" version = "0.2.2" @@ -317,6 +476,27 @@ dependencies = [ "typenum", ] +[[package]] +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", + "serde", +] + [[package]] name = "digest" version = "0.10.7" @@ -324,7 +504,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", + "const-oid", "crypto-common", + "subtle", ] [[package]] @@ -342,12 +524,57 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +dependencies = [ + "serde", +] + +[[package]] +name = "encoding_rs" +version = "0.8.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +dependencies = [ + "cfg-if", +] + [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "eyre" version = "0.6.12" @@ -358,12 +585,50 @@ dependencies = [ "once_cell", ] +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + +[[package]] +name = "finl_unicode" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" + +[[package]] +name = "flume" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" +dependencies = [ + "futures-core", + "futures-sink", + "spin 0.9.8", +] + [[package]] name = "fnv" 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.2.1" @@ -373,6 +638,20 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.30" @@ -380,6 +659,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -388,6 +668,45 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.53", +] + [[package]] name = "futures-sink" version = "0.3.30" @@ -407,9 +726,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", + "futures-io", + "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -429,8 +753,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -439,6 +765,25 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "h2" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fbd2820c5e49886948654ab546d0688ff24530286bdcf8fca3cefb16d4618eb" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "h2" version = "0.4.3" @@ -450,7 +795,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 1.1.0", "indexmap", "slab", "tokio", @@ -469,12 +814,28 @@ name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[package]] +name = "hashlink" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" +dependencies = [ + "hashbrown 0.14.3", +] [[package]] name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] [[package]] name = "hermit-abi" @@ -483,36 +844,91 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "http" -version = "1.1.0" +name = "hex" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" dependencies = [ - "bytes", - "fnv", - "itoa", + "hmac", ] [[package]] -name = "http-body" -version = "1.0.0" +name = "hmac" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "bytes", - "http", + "digest", ] [[package]] -name = "http-body-util" -version = "0.1.1" +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" dependencies = [ "bytes", "futures-core", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -528,6 +944,30 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "hyper" +version = "0.14.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.3.25", + "http 0.2.12", + "http-body 0.4.6", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + [[package]] name = "hyper" version = "1.2.0" @@ -537,9 +977,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", - "http", - "http-body", + "h2 0.4.3", + "http 1.1.0", + "http-body 1.0.0", "httparse", "httpdate", "itoa", @@ -549,6 +989,36 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-rustls" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +dependencies = [ + "futures-util", + "http 0.2.12", + "hyper 0.14.28", + "rustls", + "tokio", + "tokio-rustls", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper 1.2.0", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + [[package]] name = "hyper-util" version = "0.1.3" @@ -556,13 +1026,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" dependencies = [ "bytes", + "futures-channel", "futures-util", - "http", - "http-body", - "hyper", + "http 1.1.0", + "http-body 1.0.0", + "hyper 1.2.0", "pin-project-lite", "socket2", "tokio", + "tower", + "tower-service", + "tracing", ] [[package]] @@ -588,6 +1062,16 @@ dependencies = [ "cc", ] +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indenter" version = "0.3.3" @@ -604,6 +1088,21 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.10" @@ -635,6 +1134,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin 0.5.2", +] [[package]] name = "libc" @@ -642,12 +1144,35 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "libsqlite3-sys" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked-hash-map" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + [[package]] name = "lock_api" version = "0.4.11" @@ -656,6 +1181,7 @@ checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", + "serde", ] [[package]] @@ -664,12 +1190,31 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "matchit" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + [[package]] name = "memchr" version = "2.7.1" @@ -708,6 +1253,24 @@ dependencies = [ "windows-sys 0.48.0", ] +[[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" @@ -718,6 +1281,59 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.18" @@ -725,6 +1341,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -737,6 +1354,26 @@ dependencies = [ "libc", ] +[[package]] +name = "oauth2" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c38841cdd844847e3e7c8d29cef9dcfed8877f8f56f9071f77843ecf3baf937f" +dependencies = [ + "base64 0.13.1", + "chrono", + "getrandom", + "http 0.2.12", + "rand", + "reqwest 0.11.27", + "serde", + "serde_json", + "serde_path_to_error", + "sha2", + "thiserror", + "url", +] + [[package]] name = "object" version = "0.32.2" @@ -752,6 +1389,50 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "openssl" +version = "0.10.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "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.53", +] + +[[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.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dda2b0f344e78efc2facf7d195d098df0dd72151b26ab98da807afc26c198dff" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "ordered-multimap" version = "0.6.0" @@ -762,6 +1443,12 @@ dependencies = [ "hashbrown 0.13.2", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "owo-colors" version = "3.5.0" @@ -791,12 +1478,50 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "password-auth" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a2a4764cc1f8d961d802af27193c6f4f0124bd0e76e8393cf818e18880f0524" +dependencies = [ + "argon2", + "getrandom", + "password-hash", + "rand_core", +] + +[[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.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + [[package]] name = "pathdiff" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -834,7 +1559,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn", + "syn 2.0.53", ] [[package]] @@ -865,7 +1590,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.53", ] [[package]] @@ -880,6 +1605,45 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro2" version = "1.0.79" @@ -899,7 +1663,37 @@ dependencies = [ ] [[package]] -name = "redox_syscall" +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" @@ -907,18 +1701,180 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.6", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "reqwest" +version = "0.11.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" +dependencies = [ + "base64 0.21.7", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2 0.3.25", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.28", + "hyper-rustls", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-rustls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", + "winreg", +] + +[[package]] +name = "reqwest" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e333b1eb9fe677f6893a9efcb0d277a2d3edd83f358a236b657c32301dc6e5f6" +dependencies = [ + "base64 0.21.7", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2 0.4.3", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.2.0", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin 0.9.8", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "ron" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" dependencies = [ - "base64", + "base64 0.21.7", "bitflags 2.5.0", "serde", "serde_derive", ] +[[package]] +name = "rsa" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rust-ini" version = "0.19.0" @@ -935,6 +1891,50 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustix" +version = "0.38.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.21.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.7", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -947,6 +1947,15 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +[[package]] +name = "schannel" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -954,13 +1963,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] -name = "secrecy" -version = "0.8.0" +name = "sct" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bd1c54ea06cfd2f6b63219704de0b9b4f72dcc2b8fdef820be6cd799780e91e" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "serde", - "zeroize", + "ring", + "untrusted", +] + +[[package]] +name = "security-framework" +version = "2.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +dependencies = [ + "core-foundation-sys", + "libc", ] [[package]] @@ -980,7 +2012,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.53", ] [[package]] @@ -1030,18 +2062,44 @@ name = "server" version = "0.1.0" dependencies = [ "anyhow", + "async-trait", "axum", + "axum-login", "chrono", "color-eyre", "config", "dotenvy", - "hyper", + "hyper 1.2.0", + "log", + "oauth2", "once_cell", - "secrecy", + "password-auth", + "reqwest 0.12.1", "serde", + "serde_json", + "serde_urlencoded", + "sqlx", + "thiserror", "tokio", + "tower", "tower-http", "tracing", + "tracing-error", + "tracing-log", + "tracing-logfmt", + "tracing-subscriber", + "uuid", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", ] [[package]] @@ -1074,28 +2132,307 @@ dependencies = [ ] [[package]] -name = "slab" -version = "0.4.9" +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" + +[[package]] +name = "socket2" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlformat" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" +dependencies = [ + "itertools", + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9a2ccff1a000a5a59cd33da541d9f2fdcd9e6e8229cc200565942bff36d0aaa" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24ba59a9342a3d9bab6c56c118be528b27c9b60e490080e9711a04dccac83ef6" +dependencies = [ + "ahash", + "atoi", + "byteorder", + "bytes", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashlink", + "hex", + "indexmap", + "log", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "rustls", + "rustls-pemfile", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlformat", + "thiserror", + "time", + "tokio", + "tokio-stream", + "tracing", + "url", + "uuid", + "webpki-roots", +] + +[[package]] +name = "sqlx-macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea40e2345eb2faa9e1e5e326db8c34711317d2b5e08d0d5741619048a803127" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn 1.0.109", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5833ef53aaa16d860e92123292f1f6a3d53c34ba8b1969f152ef1a7bb803f3c8" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn 1.0.109", + "tempfile", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ed31390216d20e538e447a7a9b959e06ed9fc51c37b514b46eb758016ecd418" +dependencies = [ + "atoi", + "base64 0.21.7", + "bitflags 2.5.0", + "byteorder", + "bytes", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "time", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c824eb80b894f926f89a0b9da0c7f435d27cdd35b8c655b114e58223918577e" +dependencies = [ + "atoi", + "base64 0.21.7", + "bitflags 2.5.0", + "byteorder", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "time", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b244ef0a8414da0bed4bb1910426e890b19e5e9bccc27ada6b797d05c55ae0aa" +dependencies = [ + "atoi", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "sqlx-core", + "time", + "tracing", + "url", + "urlencoding", + "uuid", +] + +[[package]] +name = "stringprep" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "bb41d74e231a107a1b4ee36bd1214b11285b77768d2e3824aedafa988fd36ee6" dependencies = [ - "autocfg", + "finl_unicode", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "smallvec" -version = "1.13.1" +name = "subtle" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] -name = "socket2" -version = "0.5.6" +name = "syn" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "libc", - "windows-sys 0.52.0", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] @@ -1115,6 +2452,39 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "thiserror" version = "1.0.58" @@ -1132,7 +2502,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.53", ] [[package]] @@ -1145,6 +2515,37 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -1154,6 +2555,21 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.36.0" @@ -1181,7 +2597,38 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.53", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", ] [[package]] @@ -1248,6 +2695,23 @@ dependencies = [ "tracing", ] +[[package]] +name = "tower-cookies" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fd0118512cf0b3768f7fcccf0bef1ae41d68f2b45edc1e77432b36c97c56c6d" +dependencies = [ + "async-trait", + "axum-core", + "cookie", + "futures-util", + "http 1.1.0", + "parking_lot", + "pin-project-lite", + "tower-layer", + "tower-service", +] + [[package]] name = "tower-http" version = "0.5.2" @@ -1256,8 +2720,8 @@ checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" dependencies = [ "bitflags 2.5.0", "bytes", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.0", "http-body-util", "pin-project-lite", "tower-layer", @@ -1277,6 +2741,57 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" +[[package]] +name = "tower-sessions" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b7b53dbe4dc5cf64382fcbd1e8b8ca222949d757fcabec1bcc8de751bb611b" +dependencies = [ + "async-trait", + "http 1.1.0", + "time", + "tokio", + "tower-cookies", + "tower-layer", + "tower-service", + "tower-sessions-core", + "tower-sessions-memory-store", + "tracing", +] + +[[package]] +name = "tower-sessions-core" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cec154be845cc7482fa002282813881732bdf17c75a8e85ff1bddaf387b668c5" +dependencies = [ + "async-trait", + "axum-core", + "base64 0.22.0", + "futures", + "http 1.1.0", + "parking_lot", + "rand", + "serde", + "serde_json", + "thiserror", + "time", + "tokio", + "tracing", +] + +[[package]] +name = "tower-sessions-memory-store" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a9bd4f20f01924813964a7e804680dbbeec16a133c919201685d274412cba50" +dependencies = [ + "async-trait", + "time", + "tokio", + "tower-sessions-core", +] + [[package]] name = "tracing" version = "0.1.40" @@ -1297,7 +2812,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.53", ] [[package]] @@ -1320,15 +2835,58 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-logfmt" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22b8e455f6caa5212a102ec530bf86b8dc5a4c536299bffd84b238fed9119be7" +dependencies = [ + "time", + "tracing", + "tracing-core", + "tracing-subscriber", +] + +[[package]] +name = "tracing-serde" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +dependencies = [ + "serde", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "serde", + "serde_json", "sharded-slab", + "smallvec", "thread_local", + "tracing", "tracing-core", + "tracing-log", + "tracing-serde", ] [[package]] @@ -1349,24 +2907,84 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-segmentation" version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + +[[package]] +name = "uuid" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" +dependencies = [ + "serde", +] + [[package]] name = "valuable" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[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" @@ -1388,6 +3006,12 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" version = "0.2.92" @@ -1409,10 +3033,22 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.53", "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.92" @@ -1431,7 +3067,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.53", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1442,6 +3078,54 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + +[[package]] +name = "whoami" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" +dependencies = [ + "redox_syscall", + "wasite", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-core" version = "0.52.0" @@ -1592,6 +3276,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "yaml-rust" version = "0.4.5" @@ -1601,6 +3295,26 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.53", +] + [[package]] name = "zeroize" version = "1.7.0" diff --git a/server/Cargo.toml b/server/Cargo.toml index 3be3fea2..b385f9cd 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -3,19 +3,39 @@ name = "server" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +path = "src/lib.rs" + +[[bin]] +name = "server" +path = "src/main.rs" [dependencies] anyhow = { version = "1.0.81", features = ["backtrace"] } +async-trait = "0.1.78" axum = { version = "0.7.4", features = ["macros"] } +axum-login = "0.15.0" chrono = { version = "0.4.35", features = ["serde"] } color-eyre = "0.6.3" config = { version = "0.14.0", features = ["toml"] } dotenvy = "0.15.7" hyper = { version = "1.2.0", features = ["full"] } +oauth2 = "4.4.2" once_cell = "1.19.0" -secrecy = { version = "0.8.0", features = ["serde"] } +password-auth = "1.0.0" +reqwest = { version = "0.12.1", features = ["json"] } serde = "1.0.197" +serde_json = "1.0.114" +serde_urlencoded = "0.7.1" +sqlx = { version = "0.7.4", features = ["postgres", "runtime-tokio", "tls-rustls", "migrate", "uuid", "time"] } +thiserror = "1.0.58" tokio = { version = "1.36.0", features = ["full"] } tower-http = { version = "0.5.2", features = ["trace", "cors"] } tracing = "0.1.40" +tower = "0.4.13" +tracing-error = "0.2.0" +tracing-log = "0.2.0" +tracing-logfmt = "0.3.4" +tracing-subscriber = { version = "0.3.18", features = ["json", "registry", "env-filter"] } +uuid = { version = "1.8.0", features = ["serde"] } +log = "0.4.21" diff --git a/server/build.rs b/server/build.rs new file mode 100644 index 00000000..d5068697 --- /dev/null +++ b/server/build.rs @@ -0,0 +1,5 @@ +// generated by `sqlx migrate build-script` +fn main() { + // trigger recompilation when a new migration is added + println!("cargo:rerun-if-changed=migrations"); +} diff --git a/server/config/dev.toml b/server/config/dev.toml index 58ceeffa..a820754a 100644 --- a/server/config/dev.toml +++ b/server/config/dev.toml @@ -1,3 +1,5 @@ +db = "postgresql://postgres:postgres@localhost/curieo" + [log] level = "info" format = "json" diff --git a/server/migrations/20240321195639_setup.sql b/server/migrations/20240321195639_setup.sql new file mode 100644 index 00000000..0554da03 --- /dev/null +++ b/server/migrations/20240321195639_setup.sql @@ -0,0 +1,47 @@ +-- As a style choice, we prefer not to write SQL in all uppercase as lowercase feels friendlier to the eyes. +-- It's nicer to read WHEN THE CODE ISN'T YELLING AT YOU ALL DAY. +-- It perhaps made sense back when code highlighting was not the norm and case was used to differentiate keywords +-- from non-keywords, but at this point it's purely from inertia. +-- The language itself is not case-sensitive except for quoted identifiers. +-- Whichever style you use, however, consistency should still be maintained. + +-- This extension gives us `uuid_generate_v1mc()` which generates UUIDs that cluster better than `gen_random_uuid()` +-- while still being difficult to predict and enumerate. +-- Also, while unlikely, `gen_random_uuid()` can in theory produce collisions which can trigger spurious errors on +-- insertion, whereas it's much less likely with `uuid_generate_v1mc()`. +create extension if not exists "uuid-ossp"; + +-- We try to ensure every table has `created_at` and `updated_at` columns, which can help immensely with debugging +-- and auditing. +-- +-- While `created_at` can just be `default now()`, setting `updated_at` on update requires a trigger which +-- is a lot of boilerplate. These two functions save us from writing that every time as instead we can just do +-- +-- select trigger_updated_at(''); +-- +-- after a `CREATE TABLE`. +create or replace function set_updated_at() + returns trigger as +$$ +begin + NEW.updated_at = now(); +return NEW; +end; +$$ language plpgsql; + +create or replace function trigger_updated_at(tablename regclass) + returns void as +$$ +begin +execute format('CREATE TRIGGER set_updated_at + BEFORE UPDATE + ON %s + FOR EACH ROW + WHEN (OLD is distinct from NEW) + EXECUTE FUNCTION set_updated_at();', tablename); +end; +$$ language plpgsql; + +-- Finally, this is a text collation that sorts text case-insensitively, useful for `UNIQUE` indexes +-- over things like usernames and emails, without needing to remember to do case-conversion. +create collation case_insensitive (provider = icu, locale = 'und-u-ks-level2', deterministic = false); \ No newline at end of file diff --git a/server/migrations/20240321210310_users.sql b/server/migrations/20240321210310_users.sql new file mode 100644 index 00000000..32f941d9 --- /dev/null +++ b/server/migrations/20240321210310_users.sql @@ -0,0 +1,19 @@ +create table users ( + -- Having the table name as part of the primary key column makes it nicer to write joins, e.g.: + -- + -- select * from users + -- inner join article using (user_id) + -- + -- as opposed to `inner join article on article.user_id = user.id`, and makes it easier to keep track of primary + -- keys as opposed to having all PK columns named "id" + user_id uuid primary key default uuid_generate_v1mc(), + username text collate "case_insensitive" unique not null, + email text collate "case_insensitive" unique not null, + password_hash text, + access_token text, + created_at timestamptz not null default now(), + updated_at timestamptz +); + +-- And applying our `updated_at` trigger is as easy as this. +SELECT trigger_updated_at('users'); \ No newline at end of file diff --git a/server/src/auth/mod.rs b/server/src/auth/mod.rs new file mode 100644 index 00000000..a4b6579e --- /dev/null +++ b/server/src/auth/mod.rs @@ -0,0 +1,7 @@ +pub use models::*; +pub use routes::*; +pub use services::*; +pub mod models; +pub mod routes; +pub mod services; +mod utils; diff --git a/server/src/auth/models.rs b/server/src/auth/models.rs new file mode 100644 index 00000000..75a8848c --- /dev/null +++ b/server/src/auth/models.rs @@ -0,0 +1,322 @@ +use crate::auth::utils; +use crate::secrets::Secret; +use crate::telemetry::spawn_blocking_with_tracing; +use crate::users::User; +use async_trait::async_trait; +use axum::http::header::{AUTHORIZATION, USER_AGENT}; +use axum_login::{AuthnBackend, UserId}; +use oauth2::basic::{BasicClient, BasicRequestTokenError, BasicTokenResponse}; +use oauth2::reqwest::{async_http_client, AsyncHttpClientError}; +use oauth2::url::Url; +use oauth2::{ + AuthUrl, AuthorizationCode, ClientId, ClientSecret, CsrfToken, PkceCodeChallenge, + PkceCodeVerifier, RevocationUrl, TokenResponse, TokenUrl, +}; +use serde::de::Error; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use sqlx::PgPool; +use tokio::task; +use tracing::debug; + +#[derive(Deserialize, Serialize, Clone, Debug)] +#[serde(remote = "Self")] +pub struct RegisterUserRequest { + pub email: String, + pub username: String, + pub password_hash: Option>, + pub access_token: Option>, +} + +impl Serialize for RegisterUserRequest { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + Self::serialize(self, serializer) + } +} + +impl<'de> Deserialize<'de> for RegisterUserRequest { + fn deserialize>(deserializer: D) -> Result { + let s = Self::deserialize(deserializer)?; + if s.password_hash.is_some() && s.access_token.is_some() { + return Err(Error::custom("should only have password or access token")); + } + + Ok(s) + } +} + +#[derive(Debug, Clone)] +pub struct PostgresBackend { + db: PgPool, + oauth_clients: OAuth2Clients, +} + +#[derive(Debug, Clone)] +pub struct OAuth2Clients { + pub github: GitHubOAuthClient, + pub google: GoogleOAuthClient, +} + +impl Default for OAuth2Clients { + fn default() -> Self { + Self { + github: GitHubOAuthClient, + google: GoogleOAuthClient, + } + } +} + +#[async_trait] +trait OAuth2Client { + const CLIENT_ID: &'static str; + const CLIENT_SECRET: &'static str; + const AUTH_URL: &'static str; + const TOKEN_URL: &'static str; + const REVOCATION_URL: &'static str; + + fn client(&self) -> BasicClient { + BasicClient::new( + ClientId::new(Self::CLIENT_ID.to_string()), + Some(ClientSecret::new(Self::CLIENT_SECRET.to_string())), + AuthUrl::new(Self::AUTH_URL.to_string()).expect("invalid auth url"), + Some(TokenUrl::new(Self::TOKEN_URL.to_string()).expect("invalid token url")), + ) + .set_revocation_uri( + RevocationUrl::new(Self::REVOCATION_URL.to_string()).expect("invalid auth url"), + ) + } + fn authorize_url(&self, state: S) -> (Url, CsrfToken, PkceCodeVerifier) + where + S: FnOnce() -> CsrfToken, + { + let (pkce_code_challenge, pkce_code_verifier) = PkceCodeChallenge::new_random_sha256(); + let (url, token) = self + .client() + .authorize_url(state) + //.add_scope(Scope::new("user:email".to_string())) + .set_pkce_challenge(pkce_code_challenge) + .url(); + + (url, token, pkce_code_verifier) + } + async fn exchange_code( + &self, + code: AuthorizationCode, + ) -> Result> { + self.client() + .exchange_code(code) + .request_async(async_http_client) + .await + } +} + +#[derive(Debug, Clone)] +pub struct GitHubOAuthClient; + +impl OAuth2Client for GitHubOAuthClient { + const CLIENT_ID: &'static str = "github_client_id"; + const CLIENT_SECRET: &'static str = "github_client_secret"; + const AUTH_URL: &'static str = ""; + const TOKEN_URL: &'static str = ""; + const REVOCATION_URL: &'static str = ""; +} + +#[derive(Debug, Clone)] +pub struct GoogleOAuthClient; + +impl OAuth2Client for GoogleOAuthClient { + const CLIENT_ID: &'static str = ""; + const CLIENT_SECRET: &'static str = ""; + const AUTH_URL: &'static str = "https://accounts.google.com/o/oauth2/v2/auth"; + const TOKEN_URL: &'static str = "https://www.googleapis.com/oauth2/v3/token"; + const REVOCATION_URL: &'static str = "https://oauth2.googleapis.com/revoke"; +} + +impl PostgresBackend { + pub fn new(db: PgPool, oauth_clients: OAuth2Clients) -> Self { + Self { db, oauth_clients } + } + + pub fn authorize_url(&self) -> (Url, CsrfToken, PkceCodeVerifier) { + self.oauth_clients + .google + .authorize_url(CsrfToken::new_random) + } +} + +#[allow(clippy::blocks_in_conditions)] +#[async_trait] +impl AuthnBackend for PostgresBackend { + type User = User; + type Credentials = Credentials; + type Error = BackendError; + + #[tracing::instrument(level = "debug", skip(self), ret, err)] + async fn authenticate( + &self, + creds: Self::Credentials, + ) -> Result, Self::Error> { + match creds { + Credentials::Password(password_cred) => { + let user = sqlx::query_as!( + User, + "select * from users where username = $1 and password_hash is not null", + password_cred.username + ) + .fetch_optional(&self.db) + .await + .map_err(Self::Error::Sqlx)?; + + debug!("user: {:?}", user); + + // Verifying the password is blocking and potentially slow, so we do it via + // `spawn_blocking`. + spawn_blocking_with_tracing(move || { + utils::verify_user_password(user, password_cred.password) + }) + .await? + } + Credentials::OAuth(oauth_creds) => { + // Ensure the CSRF state has not been tampered with. + if oauth_creds.old_state.secret() != oauth_creds.new_state.secret() { + return Ok(None); + }; + + // Process authorization code, expecting a token response back. + let token_res = self + .oauth_clients + .github + .exchange_code(AuthorizationCode::new(oauth_creds.code)) + .await + .map_err(Self::Error::OAuth2)?; + + // Use access token to request user info. + let user_info = reqwest::Client::new() + .get("https://api.github.com/user") + .header(USER_AGENT.as_str(), "axum-login") // See: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#user-agent-required + .header( + AUTHORIZATION.as_str(), + format!("Bearer {}", token_res.access_token().secret()), + ) + .send() + .await + .map_err(Self::Error::Reqwest)? + .json::() + .await + .map_err(Self::Error::Reqwest)?; + + // Persist user in our database, so we can use `get_user`. + let user = sqlx::query_as( + r#" + insert into users (username, access_token) + values (?, ?) + on conflict(username) do update + set access_token = excluded.access_token + returning * + "#, + ) + .bind(user_info.login) + .bind(token_res.access_token().secret()) + .fetch_one(&self.db) + .await + .map_err(Self::Error::Sqlx)?; + + Ok(Some(user)) + } + } + } + + #[tracing::instrument(level = "debug", skip(self), ret, err)] + async fn get_user(&self, user_id: &UserId) -> Result, Self::Error> { + sqlx::query_as!( + Self::User, + "select * from users where user_id = $1", + user_id + ) + .fetch_optional(&self.db) + .await + .map_err(Self::Error::Sqlx) + } +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(untagged)] +pub enum Credentials { + Password(PasswordCreds), + OAuth(OAuthCreds), +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct PasswordCreds { + pub username: String, + pub password: Secret, + pub next: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct OAuthCreds { + pub code: String, + pub old_state: CsrfToken, + pub new_state: CsrfToken, +} + +#[derive(Debug, thiserror::Error)] +pub enum BackendError { + #[error(transparent)] + Sqlx(sqlx::Error), + + #[error(transparent)] + Reqwest(reqwest::Error), + + #[error(transparent)] + OAuth2(BasicRequestTokenError), + + #[error(transparent)] + TaskJoin(#[from] task::JoinError), +} + +// We use a type alias for convenience. +// +// Note that we've supplied our concrete backend here. +pub type AuthSession = axum_login::AuthSession; + +#[cfg(test)] +mod tests { + use crate::auth::models::{Credentials, OAuth2Clients, PasswordCreds}; + use crate::auth::utils::dummy_verify_password; + use crate::secrets::Secret; + + #[tokio::test] + async fn test_dummy_verify_password() { + assert!(dummy_verify_password(Secret::new("password")).is_ok()); + } + + #[tokio::test] + async fn test_oauth2_clients() { + let clients = OAuth2Clients::default(); + //let _ = clients.github.client(); + //let _ = clients.google.client(); + } + + #[test] + fn test_creds() { + let creds = Credentials::Password(PasswordCreds { + username: "test".to_string(), + password: Secret::new("password".to_string()), + next: None, + }); + println!( + "as_json: {:?}", + serde_json::to_string_pretty(&creds).unwrap() + ); + + assert_eq!(1, 2) + } +} + +#[derive(Debug, Deserialize)] +struct UserInfo { + login: String, +} diff --git a/server/src/auth/routes.rs b/server/src/auth/routes.rs new file mode 100644 index 00000000..2325bc59 --- /dev/null +++ b/server/src/auth/routes.rs @@ -0,0 +1,99 @@ +use crate::auth::models::{AuthSession, Credentials, RegisterUserRequest}; +use crate::auth::services::register; +use crate::err::AppError; +use axum::extract::State; +use axum::http::StatusCode; +use axum::response::{IntoResponse, Redirect}; +use axum::routing::{get, post}; +use axum::{Form, Json, Router}; +use color_eyre::eyre::eyre; +use sqlx::PgPool; + +use crate::startup::AppState; + +#[tracing::instrument(level = "debug", skip_all, ret, err(Debug))] +async fn register_handler( + State(pool): State, + Form(request): Form, +) -> crate::Result { + register(pool, request) + .await + .map(|user| (StatusCode::CREATED, Json(user))) +} + +#[tracing::instrument(level = "debug", skip_all)] +async fn login_handler( + mut auth_session: AuthSession, + Form(creds): Form, +) -> crate::Result<()> { + let user = match auth_session.authenticate(creds.clone()).await { + Ok(Some(user)) => user, + Ok(None) => return Err(AppError::Unauthorized), + Err(_) => return Err(eyre!("Could not authenticate user").into()), + }; + + if auth_session.login(&user).await.is_err() { + return Err(eyre!("Could not login user").into()); + } + + if let Credentials::Password(pw_creds) = creds { + //if let Some(ref next) = pw_creds.next { + // return Redirect::to(next).into_response(); + //} + } + Ok(()) +} + +#[tracing::instrument(level = "debug", skip_all)] +async fn login_callback_handler( + mut auth_session: AuthSession, + Form(creds): Form, +) -> impl IntoResponse { + let user = match auth_session.authenticate(creds.clone()).await { + Ok(Some(user)) => user, + Ok(None) => return StatusCode::UNAUTHORIZED.into_response(), + Err(_) => return StatusCode::INTERNAL_SERVER_ERROR.into_response(), + }; + + if auth_session.login(&user).await.is_err() { + return StatusCode::INTERNAL_SERVER_ERROR.into_response(); + } + + if let Credentials::Password(pw_creds) = creds { + if let Some(ref next) = pw_creds.next { + return Redirect::to(next).into_response(); + } + } + Redirect::to("/").into_response() +} + +#[tracing::instrument(level = "debug", skip_all)] +async fn logout_handler( + mut auth_session: AuthSession, + Form(creds): Form, +) -> impl IntoResponse { + let user = match auth_session.authenticate(creds.clone()).await { + Ok(Some(user)) => user, + Ok(None) => return StatusCode::UNAUTHORIZED.into_response(), + Err(_) => return StatusCode::INTERNAL_SERVER_ERROR.into_response(), + }; + + if auth_session.login(&user).await.is_err() { + return StatusCode::INTERNAL_SERVER_ERROR.into_response(); + } + + if let Credentials::Password(pw_creds) = creds { + if let Some(ref next) = pw_creds.next { + return Redirect::to(next).into_response(); + } + } + Redirect::to("/").into_response() +} + +pub fn routes() -> Router { + Router::new() + .route("/register", post(register_handler)) + .route("/login", post(login_handler)) + .route("/login_callback", get(login_callback_handler)) + .route("/logout", get(logout_handler)) +} diff --git a/server/src/auth/services.rs b/server/src/auth/services.rs new file mode 100644 index 00000000..cfc24264 --- /dev/null +++ b/server/src/auth/services.rs @@ -0,0 +1,50 @@ +use crate::auth::models::RegisterUserRequest; +use crate::auth::utils; +use crate::err::{AppError, ResultExt}; +use color_eyre::eyre::eyre; +use sqlx::PgPool; + +use crate::users::User; + +#[tracing::instrument(level = "debug", ret, err)] +pub async fn register(pool: PgPool, request: RegisterUserRequest) -> crate::Result { + if let Some(password) = request.password_hash { + let password_hash = utils::hash_password(password).await; + let user = sqlx::query_as!( + User, + "insert into users (email, username, password_hash) values ($1, $2, $3) returning *", + request.email, + request.username, + password_hash.expose() + ) + .fetch_one(&pool) + .await + .on_constraint("user_username_key", |_| { + AppError::unprocessable_entity([("username", "username taken")]) + }) + .on_constraint("user_email_key", |_| { + AppError::unprocessable_entity([("email", "email taken")]) + })?; + + return Ok(user); + } else if let Some(access_token) = request.access_token { + let user = sqlx::query_as!( + User, + "insert into users (email, username, access_token) values ($1, $2, $3) returning *", + request.email, + request.username, + access_token.expose() + ) + .fetch_one(&pool) + .await + .on_constraint("user_username_key", |_| { + AppError::unprocessable_entity([("username", "username taken")]) + }) + .on_constraint("user_email_key", |_| { + AppError::unprocessable_entity([("email", "email taken")]) + })?; + + return Ok(user); + } + Err(eyre!("Either password_hash or access_token must be provided to create a user").into()) +} diff --git a/server/src/auth/utils.rs b/server/src/auth/utils.rs new file mode 100644 index 00000000..b842b127 --- /dev/null +++ b/server/src/auth/utils.rs @@ -0,0 +1,56 @@ +use crate::auth::BackendError; +use crate::secrets::Secret; +use crate::users::User; +use password_auth::{generate_hash, verify_password}; +use sqlx::__rt::spawn_blocking; +use tracing::debug; + +#[tracing::instrument(level = "debug", ret, err)] +pub fn verify_user_password( + user: Option, + password_candidate: Secret, +) -> Result, BackendError> { + // password-based authentication. Compare our form input with an argon2 + // password hash. + // To prevent timed side-channel attacks, so we always compare the password + // hash, even if the user doesn't exist. + return match user { + // If there is no user with this username we dummy verify the password. + None => dummy_verify_password(password_candidate), + Some(user) => { + // If the user exists, but has no password, we dummy verify the password. + let Some(password_hash) = user.password_hash.expose() else { + return dummy_verify_password(password_candidate); + }; + debug!("password_hash: {:?}", password_hash); + + // If the user exists and has a password, we verify the password. + match verify_password(password_candidate.expose(), password_hash.as_ref()) { + Ok(_) => { + debug!("User authenticated: {:?}", user); + Ok(Some(user)) + } + _ => { + debug!("User not authenticated"); + Ok(None) + } + } + } + }; +} + +// Prevent side-channel attacks by always verifying the password. +pub fn dummy_verify_password(pw: Secret>) -> Result, BackendError> { + let _ = verify_password( + pw.expose_owned().as_ref(), + "$argon2id$v=19$m=15000,t=2,p=1$\ + gZiV/M1gPc22ElAH/Jh1Hw$\ + CWOrkoo7oJBQ/iyh7uJ0LO2aLEfrHwTWllSAxT0zRno", + ); + // Even if the password is correct we still return `Ok(None)`. + Ok(None) +} + +pub async fn hash_password(password: Secret) -> Secret { + spawn_blocking(move || Secret::new(generate_hash(password.expose().as_bytes()))).await +} diff --git a/server/src/err.rs b/server/src/err.rs new file mode 100644 index 00000000..9562d515 --- /dev/null +++ b/server/src/err.rs @@ -0,0 +1,192 @@ +use axum::http::header::WWW_AUTHENTICATE; +use axum::http::{HeaderMap, HeaderValue, StatusCode}; +use axum::response::{IntoResponse, Response}; +use axum::Json; +use sqlx::error::DatabaseError; +use std::borrow::Cow; +use std::collections::HashMap; +use std::fmt::Display; +use tracing::error; + +#[derive(Debug)] +pub enum AppError { + Unauthorized, + UnprocessableEntity(ErrorMap), + Sqlx(sqlx::Error), + GenericError(color_eyre::eyre::Error), +} + +impl AppError { + fn status_code(&self) -> StatusCode { + match self { + Self::Unauthorized => StatusCode::UNAUTHORIZED, + Self::UnprocessableEntity { .. } => StatusCode::UNPROCESSABLE_ENTITY, + Self::Sqlx(_) | Self::GenericError(_) => StatusCode::INTERNAL_SERVER_ERROR, + } + } + /// Convenient constructor for `Error::UnprocessableEntity`. + /// + /// Multiple for the same key are collected into a list for that key. + pub fn unprocessable_entity(errors: E) -> Self + where + ErrorMap: From, + { + Self::UnprocessableEntity(ErrorMap::from(errors)) + } +} + +impl From for AppError { + fn from(inner: color_eyre::eyre::Error) -> Self { + AppError::GenericError(inner) + } +} + +impl From for AppError { + fn from(inner: sqlx::Error) -> Self { + AppError::Sqlx(inner) + } +} + +impl Display for AppError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + AppError::GenericError(e) => write!(f, "{}", e), + AppError::Sqlx(e) => write!(f, "{}", e), + AppError::UnprocessableEntity(e) => write!(f, "{:?}", e), + AppError::Unauthorized => write!(f, "Unauthorized"), + } + } +} + +#[derive(serde::Serialize, Debug)] +pub struct ErrorMap { + errors: HashMap, Vec>>, +} + +impl From for ErrorMap +where + K: Into>, + V: Into>, + I: IntoIterator, +{ + fn from(i: I) -> Self { + let mut errors = HashMap::new(); + + for (key, val) in i { + errors + .entry(key.into()) + .or_insert_with(Vec::new) + .push(val.into()); + } + + ErrorMap { errors } + } +} + +impl IntoResponse for AppError { + fn into_response(self) -> Response { + match self { + AppError::Unauthorized => { + return ( + self.status_code(), + // Include the `WWW-Authenticate` challenge required in the specification + // for the `401 Unauthorized` response code: + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 + HeaderMap::from_iter([ + (WWW_AUTHENTICATE, HeaderValue::from_static("Basic")), + (WWW_AUTHENTICATE, HeaderValue::from_static("Bearer")), + ]), + Json(ErrorMap::from([("message", "Unauthorized")])), + ) + .into_response(); + } + AppError::UnprocessableEntity(e) => { + return (StatusCode::UNPROCESSABLE_ENTITY, Json(e)).into_response(); + } + AppError::Sqlx(ref e) => error!("SQLx error: {:?}", e), + AppError::GenericError(ref e) => error!("Generic error: {:?}", e), + }; + + // Return a http status code and json body with error message. + ( + self.status_code(), + Json(ErrorMap::from([("message", "Something went wrong")])), + ) + .into_response() + } +} + +/// A little helper trait for more easily converting database constraint errors into API errors. +/// +/// ```rust,ignore +/// let user_id = sqlx::query_scalar!( +/// r#"insert into "user" (username, email, password_hash) values ($1, $2, $3) returning user_id"#, +/// username, +/// email, +/// password_hash +/// ) +/// .fetch_one(&pool) +/// .await +/// .on_constraint("user_username_key", |_| Error::unprocessable_entity([("username", "already taken")]))?; +/// ``` +/// +/// Something like this would ideally live in a `sqlx-axum` crate if it made sense to author one, +/// however its definition is tied pretty intimately to the `Error` type, which is itself +/// tied directly to application semantics. +/// +/// To actually make this work in a generic context would make it quite a bit more complex, +/// as you'd need an intermediate error type to represent either a mapped or an unmapped error, +/// and even then it's not clear how to handle `?` in the unmapped case without more boilerplate. +pub trait ResultExt { + /// If `self` contains a SQLx database constraint error with the given name, + /// transform the error. + /// + /// Otherwise, the result is passed through unchanged. + fn on_constraint( + self, + name: &str, + f: impl FnOnce(Box) -> AppError, + ) -> Result; + + fn catch_constraints( + self, + names: &[&str], + map_err: impl FnOnce(Box) -> AppError, + ) -> Result; +} + +impl ResultExt for Result +where + E: Into, +{ + fn on_constraint( + self, + name: &str, + map_err: impl FnOnce(Box) -> AppError, + ) -> Result { + self.map_err(|e| match e.into() { + AppError::Sqlx(sqlx::Error::Database(dbe)) if dbe.constraint() == Some(name) => { + map_err(dbe) + } + e => e, + }) + } + + fn catch_constraints( + self, + names: &[&str], + map_err: impl FnOnce(Box) -> AppError, + ) -> Result { + self.map_err(|e| match e.into() { + AppError::Sqlx(sqlx::Error::Database(dbe)) => { + // TODO: Needs some extra logic to handle multiple constraints. + if names.contains(&dbe.constraint().unwrap_or_default()) { + map_err(dbe) + } else { + AppError::Sqlx(sqlx::Error::Database(dbe)) + } + } + e => e, + }) + } +} diff --git a/server/src/health_check/mod.rs b/server/src/health_check/mod.rs new file mode 100644 index 00000000..1532d6c4 --- /dev/null +++ b/server/src/health_check/mod.rs @@ -0,0 +1,4 @@ +pub use routes::*; + +mod routes; +mod selectors; diff --git a/server/src/health_check/routes.rs b/server/src/health_check/routes.rs new file mode 100644 index 00000000..c6e785b1 --- /dev/null +++ b/server/src/health_check/routes.rs @@ -0,0 +1,9 @@ +use axum::routing::get; +use axum::Router; + +use crate::health_check::selectors::health_check; +use crate::startup::AppState; + +pub fn routes() -> Router { + Router::new().route("/health", get(health_check)) +} diff --git a/server/src/health_check/selectors.rs b/server/src/health_check/selectors.rs new file mode 100644 index 00000000..97e94f21 --- /dev/null +++ b/server/src/health_check/selectors.rs @@ -0,0 +1,6 @@ +use axum::http::StatusCode; +use axum::response::IntoResponse; + +pub async fn health_check() -> impl IntoResponse { + (StatusCode::OK, "Healthy!") +} diff --git a/server/src/lib.rs b/server/src/lib.rs index 7e1b5989..e2fbfcc3 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -1,3 +1,28 @@ +use crate::telemetry::{get_subscriber, init_subscriber}; +use settings::SETTINGS; +use startup::Application; + +pub mod auth; +mod err; +mod health_check; pub mod routing; +pub mod secrets; pub mod settings; pub mod startup; +mod telemetry; +pub mod users; + +pub type Result = std::result::Result; + +pub async fn run() -> Result { + color_eyre::install()?; + + let subscriber = get_subscriber( + "search-server".into(), + SETTINGS.log.level.clone(), + SETTINGS.log.format.clone(), + ); + init_subscriber(subscriber); + + Application::build(SETTINGS.to_owned()).await +} diff --git a/server/src/main.rs b/server/src/main.rs index b734e208..757a7331 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,14 +1,6 @@ -use color_eyre::Result; -use server::settings::SETTINGS; -use server::startup::Application; +use server::{run, Result}; #[tokio::main] async fn main() -> Result<()> { - color_eyre::install()?; - - let application = Application::build(SETTINGS.to_owned()).await?; - - application.run_until_stopped().await?; - - Ok(()) + run().await?.run_until_stopped().await.map_err(Into::into) } diff --git a/server/src/routing/api.rs b/server/src/routing/api.rs index 05516ca4..608e9aa4 100644 --- a/server/src/routing/api.rs +++ b/server/src/routing/api.rs @@ -1,31 +1,56 @@ -use axum::{routing::get, Router}; -use tower_http::{ - cors::{Any, CorsLayer}, - trace::{self, TraceLayer}, -}; +use axum::Router; +use axum_login::tower_sessions::cookie::time::Duration; +use axum_login::tower_sessions::cookie::SameSite; +use axum_login::tower_sessions::{Expiry, MemoryStore, SessionManagerLayer}; +use axum_login::{login_required, AuthManagerLayerBuilder}; +use tower_http::trace::{self, TraceLayer}; use tracing::Level; +use crate::auth::models::{OAuth2Clients, PostgresBackend}; use crate::startup::AppState; +use crate::{auth, health_check, users}; -pub fn router(with_state: AppState) -> Router { - let api_routes = Router::new(); - //.nest("/auth", auth::routes()) - //.nest("/search", search::routes()) - // Health check should be accessible regardless of session middleware - //.layer(middleware::from_fn(some_auth_middleware)) - //.merge(health_check::routes()); +pub fn router(state: AppState) -> color_eyre::Result { + // Session layer. + // + // This uses `tower-sessions` to establish a layer that will provide the session + // as a request extension. + let session_store = MemoryStore::default(); + let session_layer = SessionManagerLayer::new(session_store) + .with_secure(false) + .with_same_site(SameSite::Lax) // Ensure we send the cookie from the OAuth redirect. + .with_expiry(Expiry::OnInactivity(Duration::days(1))); - Router::new() - .route("/", get(|| async { "Hello, server!" })) + //sqlx::migrate!().run(&db).await?; + + // Auth service. + // + // This combines the session layer with our backend to establish the auth + // service which will provide the auth session as a request extension. + let oauth_clients = OAuth2Clients::default(); + let backend = PostgresBackend::new(state.db.clone(), oauth_clients); + let auth_layer = AuthManagerLayerBuilder::new(backend, session_layer).build(); + let api_routes = Router::new() + //.nest("/search", search::routes()) + //.layer(middleware::from_fn(some_auth_middleware)) + .nest("/users", users::routes()) + .route_layer(login_required!( + PostgresBackend, + login_url = "/api/auth/login" + )) + // Health check should be accessible regardless of session middleware + .merge(health_check::routes()) + .nest("/auth", auth::routes()); + + Ok(Router::new() .nest("/api", api_routes) - .with_state(with_state.clone()) - // TODO: Add middleware for session management - // TODO: CORS should be configurable via settings - .layer(CorsLayer::new().allow_methods(Any).allow_origin(Any)) + .merge(health_check::routes()) + .with_state(state.clone()) + .layer(auth_layer) .layer( TraceLayer::new_for_http() .make_span_with(trace::DefaultMakeSpan::new().level(Level::INFO)) .on_failure(trace::DefaultOnFailure::new().level(Level::ERROR)) .on_response(trace::DefaultOnResponse::new().level(Level::INFO)), - ) + )) } diff --git a/server/src/secrets.rs b/server/src/secrets.rs new file mode 100644 index 00000000..7d620657 --- /dev/null +++ b/server/src/secrets.rs @@ -0,0 +1,116 @@ +use std::error::Error; +use std::fmt::{Debug, Display}; + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use sqlx::database::HasValueRef; +use sqlx::{Decode, Postgres}; + +/// A wrapper around a value that should be kept secret +/// when displayed. This is useful for fields like passwords +/// and access tokens. The value is redacted when displayed +/// or debugged. +pub struct Secret(T); + +impl Clone for Secret +where + T: Clone, +{ + fn clone(&self) -> Self { + Secret(self.0.clone()) + } +} + +impl Default for Secret +where + T: Default, +{ + fn default() -> Self { + Secret(T::default()) + } +} + +impl Secret { + pub fn new(t: T) -> Secret { + Secret(t) + } + pub fn expose(&self) -> &T { + &self.0 + } + pub fn expose_owned(self) -> T { + self.0 + } +} + +impl Display for Secret +where + T: Default + Clone + Display, +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "[redacted]") + } +} + +impl Debug for Secret +where + T: Default + Clone + Debug, +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "[redacted]") + } +} + +impl sqlx::Type for Secret +where + T: Default + Clone + sqlx::Type, +{ + fn type_info() -> sqlx::postgres::PgTypeInfo { + >::type_info() + } +} + +impl sqlx::Decode<'_, Postgres> for Secret +where + for<'a> T: sqlx::Type + sqlx::Decode<'a, Postgres> + Default + Clone, +{ + fn decode( + value: >::ValueRef, + ) -> Result> { + let value = >::decode(value)?; + Ok(Secret(value)) + } +} + +impl<'de, T> Deserialize<'de> for Secret +where + T: Deserialize<'de> + Default + Clone + Debug, +{ + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + T::deserialize(deserializer).map(Secret) + } +} + +impl Serialize for Secret +where + T: Serialize + Default + Clone + Debug, +{ + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + // We want to skip serializing the secret value + // when serializing to JSON + serializer.serialize_unit() + } +} + +impl From for Secret +where + T: Default + Clone, +{ + fn from(s: T) -> Self { + Self(s) + } +} diff --git a/server/src/settings.rs b/server/src/settings.rs index 7d25ffa5..7c0703d2 100644 --- a/server/src/settings.rs +++ b/server/src/settings.rs @@ -5,6 +5,8 @@ use dotenvy::dotenv; use once_cell::sync::Lazy; use serde::{Deserialize, Deserializer}; +use crate::secrets::Secret; + #[derive(Debug, Clone)] pub enum LogFmt { Json, @@ -28,8 +30,8 @@ impl<'de> Deserialize<'de> for LogFmt { #[derive(Debug, Clone, Deserialize)] pub struct Log { - pub format: LogFmt, pub level: String, + pub format: LogFmt, } #[derive(Debug, Clone)] @@ -75,6 +77,7 @@ pub struct Settings { pub log: Log, pub host: String, pub port: u16, + pub db: Secret, } impl Settings { diff --git a/server/src/startup.rs b/server/src/startup.rs index 8da13d62..d54dda0b 100644 --- a/server/src/startup.rs +++ b/server/src/startup.rs @@ -1,9 +1,13 @@ -use crate::routing::router; -use crate::settings::Settings; use axum::{extract::FromRef, routing::IntoMakeService, serve::Serve, Router}; -use color_eyre::Result; +use color_eyre::eyre::eyre; +use sqlx::postgres::PgPoolOptions; +use sqlx::PgPool; use tokio::net::TcpListener; +use crate::routing::router; +use crate::settings::Settings; +use crate::Result; + pub struct Application { port: u16, server: Serve, Router>, @@ -13,9 +17,14 @@ impl Application { pub async fn build(settings: Settings) -> Result { let address = format!("{}:{}", settings.host, settings.port); - let listener = TcpListener::bind(address).await?; - let port = listener.local_addr()?.port(); - let server = run(listener).await; + let listener = TcpListener::bind(address) + .await + .map_err(|e| eyre!("Failed to bind to address: {}", e))?; + let port = listener + .local_addr() + .map_err(|e| eyre!("Failed to get local address: {}", e))? + .port(); + let server = run(listener, settings).await?; Ok(Self { port, server }) } @@ -24,24 +33,42 @@ impl Application { self.port } - pub async fn run_until_stopped(self) -> Result<(), std::io::Error> { - self.server.await + pub async fn run_until_stopped(self) -> Result<()> { + Ok(self + .server + .await + .map_err(|e| eyre!("Server error: {}", e))?) } } #[derive(Clone, Debug, FromRef)] pub struct AppState { + pub db: PgPool, pub settings: Settings, } -async fn run(listener: TcpListener) -> Serve, Router> { - let state = AppState { - settings: Settings::new(), - }; +pub async fn db_connect(database_url: &str) -> Result { + match PgPoolOptions::new() + .max_connections(5) + .connect(database_url) + .await + { + Ok(pool) => Ok(pool), + Err(e) => Err(eyre!("Failed to connect to Postgres: {}", e).into()), + } +} + +async fn run( + listener: TcpListener, + settings: Settings, +) -> Result, Router>> { + let db = db_connect(settings.db.expose()).await?; + + let state = AppState { db, settings }; - let app = router(state); + let app = router(state)?; let server = axum::serve(listener, app.into_make_service()); - server + Ok(server) } diff --git a/server/src/telemetry.rs b/server/src/telemetry.rs new file mode 100644 index 00000000..1475179a --- /dev/null +++ b/server/src/telemetry.rs @@ -0,0 +1,44 @@ +use tokio::task::JoinHandle; +use tracing::{subscriber::set_global_default, Subscriber}; +use tracing_error::ErrorLayer; +use tracing_log::LogTracer; +use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry}; + +use crate::settings::LogFmt; + +pub fn get_subscriber( + _name: String, + env_filter: String, + format: LogFmt, +) -> Box { + let env_filter = EnvFilter::new(env_filter); + + let registry = Registry::default() + .with(ErrorLayer::default()) + .with(env_filter); + + match format { + LogFmt::Json => { + Box::new(registry.with(tracing_subscriber::fmt::layer().with_target(false).json())) + } + LogFmt::Pretty => { + Box::new(registry.with(tracing_subscriber::fmt::layer().with_target(false).pretty())) + } + LogFmt::Default => Box::new(registry.with(tracing_logfmt::layer())), + } +} + +pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) { + LogTracer::init().expect("Failed to set logger"); + set_global_default(subscriber).expect("Failed to set subscriber"); +} + +// Spawn a blocking task that will run the provided future, with tracing context. +pub fn spawn_blocking_with_tracing(f: F) -> JoinHandle +where + F: FnOnce() -> R + Send + 'static, + R: Send + 'static, +{ + let current_span = tracing::Span::current(); + tokio::task::spawn_blocking(move || current_span.in_scope(f)) +} diff --git a/server/src/users/mod.rs b/server/src/users/mod.rs new file mode 100644 index 00000000..5c2855f8 --- /dev/null +++ b/server/src/users/mod.rs @@ -0,0 +1,6 @@ +pub use models::*; +pub use routes::*; + +pub mod models; +pub mod routes; +pub mod selectors; diff --git a/server/src/users/models.rs b/server/src/users/models.rs new file mode 100644 index 00000000..e461aa9d --- /dev/null +++ b/server/src/users/models.rs @@ -0,0 +1,43 @@ +use crate::secrets::Secret; +use axum_login::AuthUser; +use serde::{Deserialize, Serialize}; +use sqlx::types::time; +use std::fmt::Debug; + +#[derive(sqlx::FromRow, Serialize, Deserialize, Clone)] +pub struct UserOut { + pub user_id: uuid::Uuid, + pub username: String, +} + +#[derive(sqlx::FromRow, Serialize, Deserialize, Clone, Debug)] +pub struct User { + pub user_id: uuid::Uuid, + pub email: String, + pub username: String, + pub password_hash: Secret>, + pub access_token: Secret>, + + pub created_at: time::OffsetDateTime, + pub updated_at: Option, +} + +impl AuthUser for User { + type Id = uuid::Uuid; + + fn id(&self) -> Self::Id { + self.user_id + } + + fn session_auth_hash(&self) -> &[u8] { + if let Some(access_token) = &self.access_token.expose() { + return access_token.as_bytes(); + } + + if let Some(password) = &self.password_hash.expose() { + return password.as_bytes(); + } + + &[] + } +} diff --git a/server/src/users/routes.rs b/server/src/users/routes.rs new file mode 100644 index 00000000..5ac6ed65 --- /dev/null +++ b/server/src/users/routes.rs @@ -0,0 +1,23 @@ +use crate::startup::AppState; +use crate::users::selectors::get_user; +use crate::users::User; +use axum::extract::{Path, State}; +use axum::routing::get; +use axum::{Json, Router}; +use color_eyre::eyre::eyre; +use sqlx::PgPool; + +#[tracing::instrument(level = "debug", skip_all, ret, err(Debug))] +async fn get_user_handler( + State(pool): State, + Path(user_id): Path, +) -> crate::Result> { + match get_user(pool, user_id).await? { + Some(user) => Ok(Json(user)), + None => Err(eyre!("User not found").into()), + } +} + +pub fn routes() -> Router { + Router::new().route("/:user_id", get(get_user_handler)) +} diff --git a/server/src/users/selectors.rs b/server/src/users/selectors.rs new file mode 100644 index 00000000..c3f7cc0b --- /dev/null +++ b/server/src/users/selectors.rs @@ -0,0 +1,13 @@ +use sqlx::types::uuid; +use sqlx::PgPool; + +use crate::users::User; + +#[tracing::instrument(level = "debug", ret, err)] +pub async fn get_user(pool: PgPool, user_id: uuid::Uuid) -> color_eyre::Result> { + let user = sqlx::query_as!(User, "select * from users where user_id = $1", user_id) + .fetch_optional(&pool) + .await?; + + Ok(user) +} diff --git a/server/tests/health_check.rs b/server/tests/health_check.rs new file mode 100644 index 00000000..0429370c --- /dev/null +++ b/server/tests/health_check.rs @@ -0,0 +1,28 @@ +use axum::body::Body; +use axum::http::{Request, StatusCode}; +use tower::ServiceExt; + +use server::routing::router; +use server::settings::Settings; +use server::startup::{db_connect, AppState}; + +#[tokio::test] +async fn health_check_works() { + let settings = Settings::new(); + + let db = db_connect(settings.db.expose()) + .await + .expect("Failed to connect to Postgres."); + + let state = AppState { db, settings }; + + let router = router(state).unwrap(); + let request = Request::builder() + .uri("/health") + .body(Body::empty()) + .unwrap(); + + let response = router.oneshot(request).await.unwrap(); + + assert_eq!(response.status(), StatusCode::OK); +} diff --git a/server/tests/users.rs b/server/tests/users.rs new file mode 100644 index 00000000..04eb30b1 --- /dev/null +++ b/server/tests/users.rs @@ -0,0 +1,93 @@ +use axum::body::Body; +use axum::extract::rejection::{ + FailedToDeserializeForm, FailedToDeserializeFormBody, FormRejection, RawFormRejection, +}; +use axum::extract::{FromRequest, RawForm}; +use axum::http::header::CONTENT_TYPE; +use axum::http::{Request, StatusCode}; +use axum::response::IntoResponse; +use axum::RequestExt; +use axum::{http, Form}; +use sqlx::PgPool; +use tower::ServiceExt; + +use server::auth::models::RegisterUserRequest; +use server::routing::router; +use server::secrets::Secret; +use server::settings::Settings; +use server::startup::{db_connect, AppState}; +use server::users::selectors::get_user; +use server::users::services::register_user; +/// Helper function to create a GET request for a given URI. +fn send_get_request(uri: &str) -> Request { + Request::builder() + .uri(uri) + .method("GET") + .body(Body::empty()) + .unwrap() +} + +#[sqlx::test] +async fn register_and_get_users_test(pool: PgPool) -> color_eyre::Result<()> { + let user = get_user(pool.clone(), uuid::Uuid::nil()).await.unwrap(); + assert!(user.is_none()); + + let new_user = register_user( + pool.clone(), + RegisterUserRequest { + email: "test-email".to_string(), + username: "test-username".to_string(), + password_hash: Some("password".to_string()).into(), + access_token: Default::default(), + }, + ) + .await? + .unwrap(); + + let user = get_user(pool.clone(), new_user.user_id).await?.unwrap(); + + assert_eq!(user.user_id, new_user.user_id); + assert_eq!(user.email, new_user.email); + + Ok(()) +} + +#[tokio::test] +async fn register_users_works() { + let settings = Settings::new(); + + let db = db_connect(settings.db.expose()) + .await + .expect("Failed to connect to Postgres."); + + let state = AppState { db, settings }; + let router = router(state).unwrap(); + + let form = &[ + ("email", "my-email@email.com"), + ("username", "my-username"), + ("password_hash", "my-password"), + ]; + let serialized_body = serde_urlencoded::to_string(&form).unwrap(); + let request = Request::post("/api/users/register") + .header(CONTENT_TYPE, "application/x-www-form-urlencoded") + .body(serialized_body) + .unwrap(); + + let response = router.clone().oneshot(request).await.unwrap(); + assert_eq!(response.status(), StatusCode::OK); + + let form = &[ + ("email", "my-email@email.com"), + ("username", "my-username"), + ("access_token", "my-access-token"), + ]; + let serialized_body = serde_urlencoded::to_string(&form).unwrap(); + let request = Request::post("/api/users/register") + .header(CONTENT_TYPE, "application/x-www-form-urlencoded") + .body(serialized_body) + .unwrap(); + + let response = router.oneshot(request).await.unwrap(); + assert_eq!(response.status(), StatusCode::OK); +}