Move to hyper 0.13.1!!!!

This commit is contained in:
Glenn Griffin
2019-12-17 16:00:31 -08:00
parent 348a59d96e
commit 9238153723
14 changed files with 40 additions and 72 deletions

View File

@@ -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"

View File

@@ -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"] }

View File

@@ -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)

View File

@@ -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"] }

View File

@@ -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");

View File

@@ -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"] }

View File

@@ -1,4 +1,3 @@
use tokio;
use yup_oauth2::ServiceAccountAuthenticator;
#[tokio::main]

View File

@@ -44,7 +44,7 @@ where
impl<C> Authenticator<C>
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<AccessToken, Error>
@@ -403,7 +403,7 @@ mod private {
) -> Result<TokenInfo, Error>
where
T: AsRef<str>,
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<Self::Connector>;
@@ -441,7 +441,7 @@ impl HyperClientBuilder for DefaultHyperClient {
impl<C> HyperClientBuilder for hyper::Client<C>
where
C: hyper::client::connect::Connect + 'static,
C: hyper::client::connect::Connect + Clone + Send + Sync + 'static,
{
type Connector = C;

View File

@@ -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)]

View File

@@ -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<TokenInfo, Error>
where
T: AsRef<str>,
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<TokenInfo, Error>
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<DeviceAuthResponse, Error>
where
T: AsRef<str>,
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<TokenInfo, Error>
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)
}

View File

@@ -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<TokenInfo, Error>
where
T: AsRef<str>,
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<TokenInfo, Error>
where
T: AsRef<str>,
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<TokenInfo, Error>
where
T: AsRef<str>,
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<SocketAddr>,
) -> Result<TokenInfo, Error>
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: F) -> impl Future<Output = ()>
where
F: Future<Output = ()> + '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<String>,
trigger_shutdown_tx: oneshot::Sender<()>,
shutdown_complete: Pin<Box<dyn Future<Output = ()> + 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
}
}

View File

@@ -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<C: hyper::client::connect::Connect + 'static>(
pub(crate) async fn refresh_token<C>(
client: &hyper::Client<C>,
client_secret: &ApplicationSecret,
refresh_token: &str,
) -> Result<TokenInfo, Error> {
) -> Result<TokenInfo, Error>
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

View File

@@ -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<TokenInfo, Error>
where
T: AsRef<str>,
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)
}

View File

@@ -41,7 +41,7 @@ async fn create_device_flow_auth() -> Authenticator<HttpsConnector<HttpConnector
pi: &'a DeviceAuthResponse,
) -> Pin<Box<dyn Future<Output = ()> + 'a + Send>> {
assert_eq!("https://example.com/verify", pi.verification_uri);
Box::pin(futures::future::ready(()))
Box::pin(async {})
}
}