From 4a95132ee8f24772fdb49ed3ef59fa1fadc03ece Mon Sep 17 00:00:00 2001 From: Paul Makles <paulmakles@gmail.com> Date: Mon, 28 Dec 2020 13:58:22 +0000 Subject: [PATCH] Mount rauth. --- Cargo.lock | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 5 +- src/main.rs | 9 ++-- 3 files changed, 158 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9e7f881..457e46a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,6 +30,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + [[package]] name = "async-trait" version = "0.1.42" @@ -153,6 +165,17 @@ dependencies = [ "wyz", ] +[[package]] +name = "blake2b_simd" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + [[package]] name = "block-buffer" version = "0.7.3" @@ -292,6 +315,12 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826" +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + [[package]] name = "cookie" version = "0.15.0-dev" @@ -318,6 +347,17 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" +[[package]] +name = "crossbeam-utils" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" +dependencies = [ + "autocfg 1.0.1", + "cfg-if 1.0.0", + "lazy_static", +] + [[package]] name = "crypto-mac" version = "0.7.0" @@ -419,6 +459,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "dotenv" version = "0.15.0" @@ -923,6 +969,12 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "if_chain" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f7280c75fb2e2fc47080ec80ccc481376923acb04501957fc38f935c3de5088" + [[package]] name = "indexmap" version = "1.6.1" @@ -990,6 +1042,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "json" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -1259,6 +1317,15 @@ dependencies = [ "webpki-roots 0.18.0", ] +[[package]] +name = "nanoid" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6226bc4e142124cb44e309a37a04cd9bb10e740d8642855441d3b14808f635e" +dependencies = [ + "rand 0.6.5", +] + [[package]] name = "native-tls" version = "0.2.6" @@ -1846,6 +1913,26 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "rauth" +version = "0.1.0" +source = "git+https://gitlab.insrt.uk/insert/rauth#7e6366cc0c49445355e1f176d23ad244ade6a34b" +dependencies = [ + "json", + "lazy_static", + "mongodb", + "nanoid", + "regex", + "rocket", + "rocket_contrib", + "rust-argon2", + "serde", + "snafu", + "tokio", + "ulid", + "validator", +] + [[package]] name = "rdrand" version = "0.4.0" @@ -1977,12 +2064,14 @@ dependencies = [ "num_enum", "once_cell", "rand 0.7.3", + "rauth", "reqwest", "rocket", "rocket_contrib", "rocket_cors", "serde", "serde_json", + "snafu", "time 0.2.23", "tokio", "ulid", @@ -2098,6 +2187,18 @@ dependencies = [ "version_check", ] +[[package]] +name = "rust-argon2" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" +dependencies = [ + "base64 0.13.0", + "blake2b_simd", + "constant_time_eq", + "crossbeam-utils", +] + [[package]] name = "rustc-demangle" version = "0.1.18" @@ -2350,6 +2451,28 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75" +[[package]] +name = "snafu" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eab12d3c261b2308b0d80c26fffb58d17eba81a4be97890101f416b478c79ca7" +dependencies = [ + "backtrace", + "doc-comment", + "snafu-derive", +] + +[[package]] +name = "snafu-derive" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1508efa03c362e23817f96cde18abed596a25219a8b2c66e8db33c03543d315b" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.8", + "syn 1.0.56", +] + [[package]] name = "socket2" version = "0.3.19" @@ -2925,9 +3048,9 @@ dependencies = [ [[package]] name = "validator" -version = "0.10.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e60fadf92c22236de4028ceb0b8af50ed3430d41ad43d7a7d63b6bd1a8f47c38" +checksum = "4effc922f18d14f3daf201b1d13c61e5ef62f5975e7d18df381f67badd76cfcd" dependencies = [ "idna", "lazy_static", @@ -2936,8 +3059,32 @@ dependencies = [ "serde_derive", "serde_json", "url", + "validator_derive", + "validator_types", +] + +[[package]] +name = "validator_derive" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15529099583e8ce2b070ab6a637454a1b42c7146e6daee4a6817a82bee33bd41" +dependencies = [ + "if_chain", + "lazy_static", + "proc-macro-error", + "proc-macro2 1.0.24", + "quote 1.0.8", + "regex", + "syn 1.0.56", + "validator_types", ] +[[package]] +name = "validator_types" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "add324da7950ac1f76b1c16ce8b5406147953d5d6a2ac1c5da93785f2cfc738b" + [[package]] name = "vcpkg" version = "0.2.11" diff --git a/Cargo.toml b/Cargo.toml index 23378f8..a36df61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" [dependencies] tokio = "0.2.22" many-to-many = "0.1.2" -#rauth = { git = "https://gitlab.insrt.uk/insert/rauth" } +rauth = { git = "https://gitlab.insrt.uk/insert/rauth" } hive_pubsub = { version = "0.4.1", features = ["mongo"] } rocket_cors = { git = "https://github.com/lawliet89/rocket_cors", branch = "master" } @@ -22,8 +22,9 @@ dotenv = "0.15.0" ulid = "0.4.1" serde = { version = "1.0.115", features = ["derive"] } +validator = { version = "0.11", features = ["derive"] } +snafu = { version = "0.6.9" } serde_json = "1.0.57" -validator = "0.10.1" bitfield = "0.13.2" reqwest = { version = "0.10.8", features = ["json"] } diff --git a/src/main.rs b/src/main.rs index 1f5d2bc..415f629 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ pub mod pubsub; pub mod routes; pub mod util; +use rauth; use log::info; use rocket_cors::AllowedOrigins; @@ -27,18 +28,20 @@ async fn main() { util::variables::preflight_checks(); database::connect().await; - + pubsub::hive::init_hive(); //pubsub::websocket::launch_server(); - + let cors = rocket_cors::CorsOptions { allowed_origins: AllowedOrigins::All, ..Default::default() } .to_cors() .expect("Failed to create CORS."); + + let auth = rauth::auth::Auth::new(database::get_collection("accounts")); - routes::mount(rocket::ignite()) + routes::mount(rauth::routes::mount(rocket::ignite(), "/auth", auth)) .mount("/", rocket_cors::catch_all_options_routes()) .manage(cors.clone()) .attach(cors) -- GitLab