diff --git a/src/authenticator.rs b/src/authenticator.rs index 4600040..cf866ec 100644 --- a/src/authenticator.rs +++ b/src/authenticator.rs @@ -64,7 +64,7 @@ where } /// An internal trait implemented by flows to be used by an authenticator. -pub trait TokenGetterBuilder { +pub trait AuthFlow { type TokenGetter: GetToken; fn build_token_getter(self, client: hyper::Client) -> Self::TokenGetter; @@ -74,7 +74,7 @@ pub trait TokenGetterBuilder { /// will refresh tokens as they expire as well as optionally persist tokens to /// disk. pub struct Authenticator< - T: TokenGetterBuilder, + T: AuthFlow, S: TokenStorage, AD: AuthenticatorDelegate, C: HyperClientBuilder, @@ -87,7 +87,7 @@ pub struct Authenticator< impl Authenticator where - T: TokenGetterBuilder<::Connector>, + T: AuthFlow<::Connector>, { /// Create a new authenticator with the provided flow. By default a new /// hyper::Client will be created the default authenticator delegate will be @@ -115,7 +115,7 @@ where impl Authenticator where - T: TokenGetterBuilder, + T: AuthFlow, S: TokenStorage, AD: AuthenticatorDelegate, C: HyperClientBuilder, @@ -127,7 +127,7 @@ where ) -> Authenticator> where NewC: hyper::client::connect::Connect, - T: TokenGetterBuilder, + T: AuthFlow, { Authenticator { client: hyper_client, diff --git a/src/device.rs b/src/device.rs index 684db7e..78cce65 100644 --- a/src/device.rs +++ b/src/device.rs @@ -73,7 +73,7 @@ impl DeviceFlow { } } -impl crate::authenticator::TokenGetterBuilder for DeviceFlow +impl crate::authenticator::AuthFlow for DeviceFlow where FD: FlowDelegate + Send + 'static, C: hyper::client::connect::Connect + 'static, @@ -407,7 +407,7 @@ mod tests { use tokio; use super::*; - use crate::authenticator::TokenGetterBuilder; + use crate::authenticator::AuthFlow; use crate::helper::parse_application_secret; #[test] diff --git a/src/installed.rs b/src/installed.rs index 523bfea..0ae8ae0 100644 --- a/src/installed.rs +++ b/src/installed.rs @@ -124,6 +124,40 @@ impl InstalledFlow { } } +impl InstalledFlow +where + FD: FlowDelegate, +{ + /// Use the provided FlowDelegate. + pub fn delegate(self, delegate: NewFD) -> InstalledFlow { + InstalledFlow { + method: self.method, + flow_delegate: delegate, + appsecret: self.appsecret, + } + } +} + +impl crate::authenticator::AuthFlow for InstalledFlow +where + FD: FlowDelegate + Send + 'static, + C: hyper::client::connect::Connect + 'static, +{ + type TokenGetter = InstalledFlowImpl; + + fn build_token_getter(self, client: hyper::Client) -> Self::TokenGetter { + InstalledFlowImpl { + method: self.method, + fd: self.flow_delegate, + appsecret: self.appsecret, + client, + } + } +} + +impl<'c, FD: 'static + FlowDelegate + Clone + Send, C: 'c + hyper::client::connect::Connect> + InstalledFlowImpl +{ /// Handles the token request flow; it consists of the following steps: /// . Obtain a authorization code with user cooperation or internal redirect. /// . Obtain a token and refresh token using that code. @@ -543,7 +577,7 @@ mod tests { use tokio; use super::*; - use crate::authenticator::TokenGetterBuilder; + use crate::authenticator::AuthFlow; use crate::authenticator_delegate::FlowDelegate; use crate::helper::*; use crate::types::StringError; diff --git a/src/lib.rs b/src/lib.rs index f9ad5ca..48e3b28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,7 +93,7 @@ mod service_account; mod storage; mod types; -pub use crate::authenticator::Authenticator; +pub use crate::authenticator::{AuthFlow, Authenticator}; pub use crate::authenticator_delegate::{ AuthenticatorDelegate, DefaultAuthenticatorDelegate, DefaultFlowDelegate, FlowDelegate, PollInformation,