From a656df6b74fbfaa5eec0a45b0957ae547f44c449 Mon Sep 17 00:00:00 2001 From: Lewin Bormann Date: Thu, 13 Jun 2019 15:29:18 +0200 Subject: [PATCH] feat(GetToken): Add application_secret method to GetToken trait. This makes decoupling Authenticator and individual flows easier while allowing for refreshing tokens. --- src/device.rs | 3 +++ src/installed.rs | 16 +++++++--------- src/service_account.rs | 8 +++++++- src/types.rs | 4 ++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/device.rs b/src/device.rs index f35dcd2..b58a68a 100644 --- a/src/device.rs +++ b/src/device.rs @@ -55,6 +55,9 @@ impl< fn api_key(&mut self) -> Option { None } + fn application_secret(&self) -> ApplicationSecret { + self.application_secret.clone() + } } impl DeviceFlow diff --git a/src/installed.rs b/src/installed.rs index 1a5a0d1..9190edd 100644 --- a/src/installed.rs +++ b/src/installed.rs @@ -61,10 +61,8 @@ where }) } -impl< - FD: FlowDelegate + 'static + Send + Clone, - C: hyper::client::connect::Connect + 'static, - > GetToken for InstalledFlow +impl + GetToken for InstalledFlow { fn token<'b, I, T>( &mut self, @@ -79,6 +77,9 @@ impl< fn api_key(&mut self) -> Option { None } + fn application_secret(&self) -> ApplicationSecret { + self.appsecret.clone() + } } pub struct InstalledFlow { @@ -99,11 +100,8 @@ pub enum InstalledFlowReturnMethod { HTTPRedirect(u16), } -impl< - 'c, - FD: 'static + FlowDelegate + Clone + Send, - C: 'c + hyper::client::connect::Connect, - > InstalledFlow +impl<'c, FD: 'static + FlowDelegate + Clone + Send, C: 'c + hyper::client::connect::Connect> + InstalledFlow { /// Starts a new Installed App auth flow. /// If HTTPRedirect is chosen as method and the server can't be started, the flow falls diff --git a/src/service_account.rs b/src/service_account.rs index 9539f1d..eeb78e0 100644 --- a/src/service_account.rs +++ b/src/service_account.rs @@ -16,7 +16,7 @@ use std::error; use std::sync::{Arc, Mutex}; use crate::storage::{hash_scopes, MemoryStorage, TokenStorage}; -use crate::types::{GetToken, StringError, Token}; +use crate::types::{ApplicationSecret, GetToken, StringError, Token}; use futures::stream::Stream; use futures::{future, prelude::*}; @@ -358,6 +358,12 @@ where ) } + /// Returns an empty ApplicationSecret as tokens for service accounts don't need to be + /// refreshed (they are simply reissued). + fn application_secret(&self) -> ApplicationSecret { + Default::default() + } + fn api_key(&mut self) -> Option { None } diff --git a/src/types.rs b/src/types.rs index 2f353f9..3ba1586 100644 --- a/src/types.rs +++ b/src/types.rs @@ -205,6 +205,10 @@ pub trait GetToken { I: Iterator; fn api_key(&mut self) -> Option; + + /// Return an application secret with at least token_uri, client_secret, and client_id filled + /// in. This is used for refreshing tokens without interaction from the flow. + fn application_secret(&self) -> ApplicationSecret; } /// Represents a token as returned by OAuth2 servers.