From 6e4503f55ebe82d0a45a896e1170857a73756397 Mon Sep 17 00:00:00 2001 From: Daniel Rodgers-Pryor Date: Thu, 25 Mar 2021 21:20:21 +1100 Subject: [PATCH] Simplify with_storage interface By only allowing a custom storage. To use one of the built-in storage mechanism, there is already a special-purpose `persist_tokens_to_disk` method available. --- examples/custom_storage.rs | 8 +++----- src/authenticator.rs | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/custom_storage.rs b/examples/custom_storage.rs index e78ad3c..6d44226 100644 --- a/examples/custom_storage.rs +++ b/examples/custom_storage.rs @@ -74,11 +74,9 @@ async fn main() { sec, yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect, ) - .with_storage(yup_oauth2::authenticator::StorageType::Custom(Box::new( - ExampleTokenStore { - store: RwLock::new(vec![]), - }, - ))) + .with_storage(Box::new(ExampleTokenStore { + store: RwLock::new(vec![]), + })) .build() .await .expect("InstalledFlowAuthenticator failed to build"); diff --git a/src/authenticator.rs b/src/authenticator.rs index bd2cf83..a23a18a 100644 --- a/src/authenticator.rs +++ b/src/authenticator.rs @@ -238,9 +238,9 @@ impl AuthenticatorBuilder { } /// Use the provided token storage mechanism - pub fn with_storage(self, storage_type: StorageType) -> Self { + pub fn with_storage(self, storage: Box) -> Self { AuthenticatorBuilder { - storage_type: storage_type, + storage_type: StorageType::Custom(storage), ..self } } @@ -504,7 +504,7 @@ where } /// How should the acquired tokens be stored? -pub enum StorageType { +enum StorageType { /// Store tokens in memory (and always log in again to acquire a new token on startup) Memory, /// Store tokens to disk in the given file. Warning, this may be insecure unless you configure your operating system to restrict read access to the file.