diff --git a/src/authenticator_delegate.rs b/src/authenticator_delegate.rs index 7537bc2..2f3933f 100644 --- a/src/authenticator_delegate.rs +++ b/src/authenticator_delegate.rs @@ -80,19 +80,26 @@ pub trait DeviceFlowDelegate: Send + Sync { /// along with the `verification_uri`. /// # Notes /// * Will be called exactly once, provided we didn't abort during `request_code` phase. - fn present_user_code(&self, pi: &DeviceAuthResponse) { - println!( - "Please enter {} at {} and grant access to this application", - pi.user_code, pi.verification_uri - ); - println!("Do not close this application until you either denied or granted access."); - println!( - "You have time until {}.", - pi.expires_at.with_timezone(&Local) - ); + fn present_user_code<'a>( + &'a self, + device_auth_resp: &'a DeviceAuthResponse, + ) -> Pin + Send + 'a>> { + Box::pin(present_user_code(device_auth_resp)) } } +async fn present_user_code(device_auth_resp: &DeviceAuthResponse) { + println!( + "Please enter {} at {} and grant access to this application", + device_auth_resp.user_code, device_auth_resp.verification_uri + ); + println!("Do not close this application until you either denied or granted access."); + println!( + "You have time until {}.", + device_auth_resp.expires_at.with_timezone(&Local) + ); +} + /// InstalledFlowDelegate methods are called when an installed flow needs to ask /// the application what to do in certain cases. pub trait InstalledFlowDelegate: Send + Sync { diff --git a/src/device.rs b/src/device.rs index e32e6fa..6888091 100644 --- a/src/device.rs +++ b/src/device.rs @@ -55,7 +55,9 @@ impl DeviceFlow { scopes, ) .await?; - self.flow_delegate.present_user_code(&device_auth_resp); + self.flow_delegate + .present_user_code(&device_auth_resp) + .await; self.wait_for_device_token( hyper_client, &self.app_secret, @@ -193,6 +195,7 @@ impl DeviceFlow { #[cfg(test)] mod tests { use hyper_rustls::HttpsConnector; + use std::pin::Pin; use super::*; @@ -201,8 +204,12 @@ mod tests { #[derive(Clone)] struct FD; impl DeviceFlowDelegate for FD { - fn present_user_code(&self, pi: &DeviceAuthResponse) { + fn present_user_code<'a>( + &'a self, + pi: &'a DeviceAuthResponse, + ) -> Pin + 'a + Send>> { assert_eq!("https://example.com/verify", pi.verification_uri); + Box::pin(futures::future::ready(())) } }