diff --git a/Cargo.toml b/Cargo.toml index d9a377a..ffcb393 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,18 +13,16 @@ edition = "2018" [dependencies] base64 = "0.10" chrono = { version = "0.4", features = ["serde"] } -http = "0.1" -hyper = {version = "0.13.0-alpha.4", features = ["unstable-stream"]} -hyper-rustls = "=0.18.0-alpha.2" +http = "0.2" +hyper = "0.13.1" +hyper-rustls = "0.19" log = "0.4" rustls = "0.16" +seahash = "3.0.6" serde = {version = "1.0", features = ["derive"]} serde_json = "1.0" +tokio = { version = "0.2", features = ["fs", "macros", "io-std", "time"] } url = "1" -futures-preview = "=0.3.0-alpha.19" -tokio = "=0.2.0-alpha.6" -futures-util-preview = "=0.3.0-alpha.19" -seahash = "3.0.6" [dev-dependencies] mockito = "0.17" diff --git a/examples/test-device/Cargo.toml b/examples/test-device/Cargo.toml index 39ca484..3cf49c5 100644 --- a/examples/test-device/Cargo.toml +++ b/examples/test-device/Cargo.toml @@ -6,7 +6,4 @@ edition = "2018" [dependencies] yup-oauth2 = { path = "../../" } -hyper = {version = "0.13.0-alpha.4", features = ["unstable-stream"]} -hyper-rustls = "=0.18.0-alpha.2" -futures-preview = "=0.3.0-alpha.19" -tokio = "=0.2.0-alpha.6" +tokio = { version = "0.2", features = ["macros"] } \ No newline at end of file diff --git a/examples/test-device/src/main.rs b/examples/test-device/src/main.rs index 6d505b4..6586d40 100644 --- a/examples/test-device/src/main.rs +++ b/examples/test-device/src/main.rs @@ -1,11 +1,8 @@ use yup_oauth2::DeviceFlowAuthenticator; -use std::path; -use tokio; - #[tokio::main] async fn main() { - let app_secret = yup_oauth2::read_application_secret(path::Path::new("clientsecret.json")) + let app_secret = yup_oauth2::read_application_secret("clientsecret.json") .await .expect("clientsecret"); let auth = DeviceFlowAuthenticator::builder(app_secret) diff --git a/examples/test-installed/Cargo.toml b/examples/test-installed/Cargo.toml index e7fa5d2..6b69312 100644 --- a/examples/test-installed/Cargo.toml +++ b/examples/test-installed/Cargo.toml @@ -6,7 +6,4 @@ edition = "2018" [dependencies] yup-oauth2 = { path = "../../" } -hyper = {version = "0.13.0-alpha.4", features = ["unstable-stream"]} -hyper-rustls = "=0.18.0-alpha.2" -futures-preview = "=0.3.0-alpha.19" -tokio = "=0.2.0-alpha.6" +tokio = { version = "0.2", features = ["macros"] } diff --git a/examples/test-installed/src/main.rs b/examples/test-installed/src/main.rs index c59f9c9..43a797c 100644 --- a/examples/test-installed/src/main.rs +++ b/examples/test-installed/src/main.rs @@ -1,10 +1,8 @@ use yup_oauth2::{InstalledFlowAuthenticator, InstalledFlowReturnMethod}; -use std::path::Path; - #[tokio::main] async fn main() { - let app_secret = yup_oauth2::read_application_secret(Path::new("clientsecret.json")) + let app_secret = yup_oauth2::read_application_secret("clientsecret.json") .await .expect("clientsecret.json"); diff --git a/examples/test-svc-acct/Cargo.toml b/examples/test-svc-acct/Cargo.toml index 14c7d9b..abc2694 100644 --- a/examples/test-svc-acct/Cargo.toml +++ b/examples/test-svc-acct/Cargo.toml @@ -6,7 +6,4 @@ edition = "2018" [dependencies] yup-oauth2 = { path = "../../" } -hyper = {version = "0.13.0-alpha.4", features = ["unstable-stream"]} -hyper-rustls = "=0.18.0-alpha.2" -futures-preview = "=0.3.0-alpha.19" -tokio = "=0.2.0-alpha.6" +tokio = { version = "0.2", features = ["macros"] } diff --git a/examples/test-svc-acct/src/main.rs b/examples/test-svc-acct/src/main.rs index ee79ece..ee67c03 100644 --- a/examples/test-svc-acct/src/main.rs +++ b/examples/test-svc-acct/src/main.rs @@ -1,4 +1,3 @@ -use tokio; use yup_oauth2::ServiceAccountAuthenticator; #[tokio::main] diff --git a/src/authenticator.rs b/src/authenticator.rs index 6b71424..0500e67 100644 --- a/src/authenticator.rs +++ b/src/authenticator.rs @@ -44,7 +44,7 @@ where impl Authenticator where - C: hyper::client::connect::Connect + 'static, + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, { /// Return the current token for the provided scopes. pub async fn token<'a, T>(&'a self, scopes: &'a [T]) -> Result @@ -403,7 +403,7 @@ mod private { ) -> Result where T: AsRef, - C: hyper::client::connect::Connect + 'static, + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, { match self { AuthFlow::DeviceFlow(device_flow) => device_flow.token(hyper_client, scopes).await, @@ -421,7 +421,7 @@ mod private { /// A trait implemented for any hyper::Client as well as the DefaultHyperClient. pub trait HyperClientBuilder { /// The hyper connector that the resulting hyper client will use. - type Connector: hyper::client::connect::Connect + 'static; + type Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static; /// Create a hyper::Client fn build_hyper_client(self) -> hyper::Client; @@ -441,7 +441,7 @@ impl HyperClientBuilder for DefaultHyperClient { impl HyperClientBuilder for hyper::Client where - C: hyper::client::connect::Connect + 'static, + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, { type Connector = C; diff --git a/src/authenticator_delegate.rs b/src/authenticator_delegate.rs index 2f3933f..6308bd5 100644 --- a/src/authenticator_delegate.rs +++ b/src/authenticator_delegate.rs @@ -5,7 +5,7 @@ use std::pin::Pin; use std::time::Duration; use chrono::{DateTime, Local, Utc}; -use futures::prelude::*; +use std::future::Future; /// Contains state of pending authentication requests #[derive(Clone, Debug, PartialEq)] diff --git a/src/device.rs b/src/device.rs index 092cb80..70f0780 100644 --- a/src/device.rs +++ b/src/device.rs @@ -7,7 +7,6 @@ use crate::types::{ApplicationSecret, TokenInfo}; use std::borrow::Cow; use std::time::Duration; -use futures::prelude::*; use hyper::header; use url::form_urlencoded; @@ -46,7 +45,7 @@ impl DeviceFlow { ) -> Result where T: AsRef, - C: hyper::client::connect::Connect + 'static, + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, { let device_auth_resp = Self::request_code( &self.app_secret, @@ -76,12 +75,12 @@ impl DeviceFlow { grant_type: &str, ) -> Result where - C: hyper::client::connect::Connect + 'static, + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, { let mut interval = device_auth_resp.interval; log::debug!("Polling every {:?} for device token", interval); loop { - tokio::timer::delay_for(interval).await; + tokio::time::delay_for(interval).await; interval = match Self::poll_token( &app_secret, hyper_client, @@ -133,7 +132,7 @@ impl DeviceFlow { ) -> Result where T: AsRef, - C: hyper::client::connect::Connect + 'static, + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, { let req = form_urlencoded::Serializer::new(String::new()) .extend_pairs(&[ @@ -150,7 +149,7 @@ impl DeviceFlow { .unwrap(); log::debug!("requesting code from server: {:?}", req); let (head, body) = client.request(req).await?.into_parts(); - let body = body.try_concat().await?; + let body = hyper::body::to_bytes(body).await?; log::debug!("received response; head: {:?}, body: {:?}", head, body); DeviceAuthResponse::from_json(&body) } @@ -180,7 +179,7 @@ impl DeviceFlow { grant_type: &str, ) -> Result where - C: hyper::client::connect::Connect + 'static, + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, { // We should be ready for a new request let req = form_urlencoded::Serializer::new(String::new()) @@ -198,7 +197,7 @@ impl DeviceFlow { .unwrap(); // TODO: Error checking log::debug!("polling for token: {:?}", request); let (head, body) = client.request(request).await?.into_parts(); - let body = body.try_concat().await?; + let body = hyper::body::to_bytes(body).await?; log::debug!("received response; head: {:?} body: {:?}", head, body); TokenInfo::from_json(&body) } diff --git a/src/installed.rs b/src/installed.rs index fd85154..3611162 100644 --- a/src/installed.rs +++ b/src/installed.rs @@ -7,13 +7,9 @@ use crate::error::Error; use crate::types::{ApplicationSecret, TokenInfo}; use std::convert::AsRef; -use std::future::Future; use std::net::SocketAddr; -use std::pin::Pin; use std::sync::{Arc, Mutex}; -use futures::future::FutureExt; -use futures_util::try_stream::TryStreamExt; use hyper::header; use tokio::sync::oneshot; use url::form_urlencoded; @@ -96,7 +92,7 @@ impl InstalledFlow { ) -> Result where T: AsRef, - C: hyper::client::connect::Connect + 'static, + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, { match self.method { InstalledFlowReturnMethod::HTTPRedirect => { @@ -118,7 +114,7 @@ impl InstalledFlow { ) -> Result where T: AsRef, - C: hyper::client::connect::Connect + 'static, + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, { let url = build_authentication_request_url( &app_secret.auth_uri, @@ -145,7 +141,7 @@ impl InstalledFlow { ) -> Result where T: AsRef, - C: hyper::client::connect::Connect + 'static, + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, { use std::borrow::Cow; let server = InstalledFlowServer::run()?; @@ -182,13 +178,13 @@ impl InstalledFlow { server_addr: Option, ) -> Result where - C: hyper::client::connect::Connect + 'static, + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, { let redirect_uri = self.flow_delegate.redirect_uri(); let request = Self::request_token(app_secret, authcode, redirect_uri, server_addr); log::debug!("Sending request: {:?}", request); let (head, body) = hyper_client.request(request).await?.into_parts(); - let body = body.try_concat().await?; + let body = hyper::body::to_bytes(body).await?; log::debug!("Received response; head: {:?} body: {:?}", head, body); TokenInfo::from_json(&body) } @@ -224,22 +220,11 @@ impl InstalledFlow { } } -fn spawn_with_handle(f: F) -> impl Future -where - F: Future + 'static + Send, -{ - let (tx, rx) = oneshot::channel(); - tokio::spawn(f.map(move |_| tx.send(()).unwrap())); - async { - let _ = rx.await; - } -} - struct InstalledFlowServer { addr: SocketAddr, auth_code_rx: oneshot::Receiver, trigger_shutdown_tx: oneshot::Sender<()>, - shutdown_complete: Pin + Send>>, + shutdown_complete: tokio::task::JoinHandle<()>, } impl InstalledFlowServer { @@ -262,7 +247,7 @@ impl InstalledFlowServer { let server = hyper::server::Server::try_bind(&addr)?; let server = server.http1_only(true).serve(service); let addr = server.local_addr(); - let shutdown_complete = spawn_with_handle(async { + let shutdown_complete = tokio::spawn(async { let _ = server .with_graceful_shutdown(async move { let _ = trigger_shutdown_rx.await; @@ -274,7 +259,7 @@ impl InstalledFlowServer { addr, auth_code_rx, trigger_shutdown_tx, - shutdown_complete: Box::pin(shutdown_complete), + shutdown_complete, }) } @@ -293,7 +278,7 @@ impl InstalledFlowServer { log::debug!("Shutting down HTTP server"); // auth code received. shutdown the server let _ = self.trigger_shutdown_tx.send(()); - self.shutdown_complete.await; + let _ = self.shutdown_complete.await; auth_code } } diff --git a/src/refresh.rs b/src/refresh.rs index 3e28f87..53d12fa 100644 --- a/src/refresh.rs +++ b/src/refresh.rs @@ -1,7 +1,6 @@ use crate::error::Error; use crate::types::{ApplicationSecret, TokenInfo}; -use futures_util::try_stream::TryStreamExt; use hyper::header; use url::form_urlencoded; @@ -27,11 +26,14 @@ impl RefreshFlow { /// /// # Examples /// Please see the crate landing page for an example. - pub(crate) async fn refresh_token( + pub(crate) async fn refresh_token( client: &hyper::Client, client_secret: &ApplicationSecret, refresh_token: &str, - ) -> Result { + ) -> Result + where + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, + { log::debug!( "refreshing access token with refresh token: {}", refresh_token @@ -51,7 +53,7 @@ impl RefreshFlow { .unwrap(); log::debug!("Sending request: {:?}", request); let (head, body) = client.request(request).await?.into_parts(); - let body = body.try_concat().await?; + let body = hyper::body::to_bytes(body).await?; log::debug!("Received response; head: {:?}, body: {:?}", head, body); let mut token = TokenInfo::from_json(&body)?; // If the refresh result contains a refresh_token use it, otherwise diff --git a/src/service_account.rs b/src/service_account.rs index 2427f7c..81d4c6e 100644 --- a/src/service_account.rs +++ b/src/service_account.rs @@ -16,7 +16,6 @@ use crate::types::TokenInfo; use std::io; -use futures::prelude::*; use hyper::header; use rustls::{ self, @@ -184,7 +183,7 @@ impl ServiceAccountFlow { ) -> Result where T: AsRef, - C: hyper::client::connect::Connect + 'static, + C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, { let claims = Claims::new(&self.key, scopes, self.subject.as_ref().map(|x| x.as_str())); let signed = self.signer.sign_claims(&claims).map_err(|_| { @@ -202,7 +201,7 @@ impl ServiceAccountFlow { .unwrap(); log::debug!("requesting token from service account: {:?}", request); let (head, body) = hyper_client.request(request).await?.into_parts(); - let body = body.try_concat().await?; + let body = hyper::body::to_bytes(body).await?; log::debug!("received response; head: {:?}, body: {:?}", head, body); TokenInfo::from_json(&body) } diff --git a/tests/tests.rs b/tests/tests.rs index 44ff000..4f75991 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -41,7 +41,7 @@ async fn create_device_flow_auth() -> Authenticator Pin + 'a + Send>> { assert_eq!("https://example.com/verify", pi.verification_uri); - Box::pin(futures::future::ready(())) + Box::pin(async {}) } }