feat(Authenticator client): Accept custom connectors

Update Authenticator to accept clients with custom connectors, rather
than depending on the sealed hyper::client::connect::Connect trait, as recommended by hyper: https://docs.rs/hyper/0.13.8/src/hyper/client/connect/mod.rs.html#256-258

Closes #177.
This commit is contained in:
Kyle Gentle
2022-05-21 00:00:13 -04:00
committed by Kyle Gentle
parent 253528a1fe
commit c76ae18224
9 changed files with 146 additions and 55 deletions

View File

@@ -5,12 +5,22 @@
//!
//! It is also a better use of resources (memory, sockets, etc.)
async fn r#use<C>(
client: hyper::Client<C>,
authenticator: yup_oauth2::authenticator::Authenticator<C>,
use std::error::Error as StdError;
use hyper::client::connect::Connection;
use http::Uri;
use tokio::io::{AsyncRead, AsyncWrite};
use tower_service::Service;
async fn r#use<S>(
client: hyper::Client<S>,
authenticator: yup_oauth2::authenticator::Authenticator<S>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>>
where
C: Clone + Send + Sync + hyper::client::connect::Connect + 'static,
S: Service<Uri> + Clone + Send + Sync + 'static,
S::Response: Connection + AsyncRead + AsyncWrite + Send + Unpin + 'static,
S::Future: Send + Unpin + 'static,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
{
let token = authenticator.token(&["email"]).await?;
let request = http::Request::get("https://example.com")