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.
This commit is contained in:
Daniel Rodgers-Pryor
2021-03-25 21:20:21 +11:00
parent 089543f6c9
commit 6e4503f55e
2 changed files with 6 additions and 8 deletions

View File

@@ -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");

View File

@@ -238,9 +238,9 @@ impl<C, F> AuthenticatorBuilder<C, F> {
}
/// Use the provided token storage mechanism
pub fn with_storage(self, storage_type: StorageType) -> Self {
pub fn with_storage(self, storage: Box<dyn TokenStorage>) -> 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.