Major refactor of the public API.

1) Remove the GetToken trait. The trait seemed to be organically
designed. It appeared to be mostly tailored for simplifying the
implementation since there was no way for users to provide their own
implementation to Authenticator. It sadly seemed to get in the way of
implementations more than it helped. An enum representing the known
implementations is a more straightforward way to accomplish the goal and
also has the benefit of not requiring Boxing when returning features
(which admittedly is a minor concern for this use case).

2) Reduce the number of type parameters by using trait object for
delegates. This simplifies the code considerably and the performance
impact of virtual dispatch for the delegate calls is a non-factor.

3) With the above two simplifications it became easier to unify the
public interface for building an authenticator. See the examples for how
InstalledFlow, DeviceFlow, and ServiceAccount authenticators are now created.
This commit is contained in:
Glenn Griffin
2019-11-13 11:51:28 -08:00
parent 911fec82f1
commit 3aadc6b0ef
9 changed files with 519 additions and 653 deletions

View File

@@ -1,13 +1,13 @@
use yup_oauth2::{self, Authenticator, DeviceFlow, GetToken};
use yup_oauth2::DeviceFlowAuthenticator;
use std::path;
use tokio;
#[tokio::main]
async fn main() {
let creds = yup_oauth2::read_application_secret(path::Path::new("clientsecret.json"))
let app_secret = yup_oauth2::read_application_secret(path::Path::new("clientsecret.json"))
.expect("clientsecret");
let auth = Authenticator::new(DeviceFlow::new(creds))
let auth = DeviceFlowAuthenticator::builder(app_secret)
.persist_tokens_to_disk("tokenstorage.json")
.build()
.await