diff options
| author | Jesse Morgan <jesse@jesterpm.net> | 2020-09-18 21:41:36 -0700 | 
|---|---|---|
| committer | Jesse Morgan <jesse@jesterpm.net> | 2020-09-18 21:41:36 -0700 | 
| commit | 1cdfdeddbce256f26a7a7d4eae0ed2aacbcf8661 (patch) | |
| tree | 710595ddfc99e261d51e4be237221e7b122e8ffb | |
| parent | 89734a74faed3c330bed569ac36b6480da8ed8d9 (diff) | |
Replace reqwest with actix_web::client
| -rw-r--r-- | Cargo.lock | 107 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/oauth.rs | 42 | 
3 files changed, 40 insertions, 111 deletions
| @@ -1203,16 +1203,10 @@ dependencies = [   "socket2",   "widestring",   "winapi 0.3.9", - "winreg 0.6.2", + "winreg",  ]  [[package]] -name = "ipnet" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" - -[[package]]  name = "itoa"  version = "0.4.6"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1229,15 +1223,6 @@ dependencies = [  ]  [[package]] -name = "js-sys" -version = "0.3.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8" -dependencies = [ - "wasm-bindgen", -] - -[[package]]  name = "kernel32-sys"  version = "0.2.2"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1350,16 +1335,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"  checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"  [[package]] -name = "mime_guess" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" -dependencies = [ - "mime", - "unicase", -] - -[[package]]  name = "miniz_oxide"  version = "0.3.7"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1807,42 +1782,6 @@ dependencies = [  ]  [[package]] -name = "reqwest" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9eaa17ac5d7b838b7503d118fa16ad88f440498bf9ffe5424e621f93190d61e" -dependencies = [ - "base64 0.12.3", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "http", - "http-body", - "hyper", - "hyper-tls", - "ipnet", - "js-sys", - "lazy_static", - "log", - "mime", - "mime_guess", - "native-tls", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-tls", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg 0.7.0", -] - -[[package]]  name = "resolv-conf"  version = "0.6.3"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1981,13 +1920,13 @@ dependencies = [   "base32",   "bytes",   "chrono", + "derive_more",   "env_logger",   "futures",   "image",   "log",   "mime",   "rand", - "reqwest",   "rusoto_core",   "rusoto_s3",   "serde", @@ -2526,15 +2465,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"  checksum = "eeba86d422ce181a719445e51872fa30f1f7413b62becb52e95ec91aa262d85c"  [[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - -[[package]]  name = "unicode-bidi"  version = "0.3.4"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2616,8 +2546,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"  checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42"  dependencies = [   "cfg-if", - "serde", - "serde_json",   "wasm-bindgen-macro",  ] @@ -2637,18 +2565,6 @@ dependencies = [  ]  [[package]] -name = "wasm-bindgen-futures" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]]  name = "wasm-bindgen-macro"  version = "0.2.68"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2678,16 +2594,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"  checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"  [[package]] -name = "web-sys" -version = "0.3.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]]  name = "widestring"  version = "0.4.2"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2746,15 +2652,6 @@ dependencies = [  ]  [[package]] -name = "winreg" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" -dependencies = [ - "winapi 0.3.9", -] - -[[package]]  name = "ws2_32-sys"  version = "0.2.1"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -17,13 +17,13 @@ bytes = "0.5"  futures = "0.3"  chrono = { version = "0.4", features = ["serde"] } +derive_more = "0.99.9"  serde = { version = "1.0", features = ["derive"] }  serde_json = "1.0"  base32 = "0.4"  mime = "0.3"  rand = "0.7" -reqwest = { version = "0.10", features = ["json"] }  rusoto_core = "0.45.0"  rusoto_s3 = "0.45.0" diff --git a/src/oauth.rs b/src/oauth.rs index 8707b1a..4d9bd1e 100644 --- a/src/oauth.rs +++ b/src/oauth.rs @@ -1,5 +1,9 @@ +use actix_web::client::Client; +use actix_web::error::Error; +use actix_web::http::{header, StatusCode}; +use actix_web::ResponseError; +use derive_more::Display;  use futures::{FutureExt, TryFutureExt}; -use reqwest::header;  use serde::{Deserialize, Serialize};  /// Representation of an OAuth Access Token @@ -27,7 +31,7 @@ impl AccessToken {  /// Verification Service takes an Authorization header and checks if it's valid.  pub struct VerificationService {      token_endpoint: String, -    client: reqwest::Client, +    client: Client,  }  impl VerificationService { @@ -37,7 +41,7 @@ impl VerificationService {      {          VerificationService {              token_endpoint: token_endpoint.into(), -            client: reqwest::Client::new(), +            client: Client::new(),          }      } @@ -46,8 +50,36 @@ impl VerificationService {              .get(&self.token_endpoint)              .header(header::AUTHORIZATION, auth_token)              .send() -            .map(|res| res.and_then(|r| r.error_for_status())) -            .and_then(|resp| resp.json()) +            .map_err(Error::from) +            .map(|res| { +                res.and_then(|r| { +                    if r.status().is_success() { +                        Ok(r) +                    } else if r.status() == StatusCode::UNAUTHORIZED { +                        Err(VerificationError::Unauthenticated.into()) +                    } else { +                        Err(VerificationError::InternalError( +                            r.status() +                                .canonical_reason() +                                .unwrap_or("Unknown Error") +                                .to_string(), +                        ) +                        .into()) +                    } +                }) +            }) +            .map_err(Error::from) +            .and_then(|mut resp| resp.json().map_err(Error::from))              .await      }  } + +#[derive(Display, Debug)] +pub enum VerificationError { +    #[display(fmt = "Unauthenticated")] +    Unauthenticated, +    #[display(fmt = "AuthServer Error")] +    InternalError(String), +} + +impl ResponseError for VerificationError {} | 
