refactor(DeviceFlow): Make DeviceFlow work with Futures

This commit is contained in:
Lewin Bormann
2019-06-12 18:43:30 +02:00
parent 732e594962
commit 58383f9a03
6 changed files with 240 additions and 136 deletions

View File

@@ -0,0 +1,12 @@
[package]
name = "test-device"
version = "0.1.0"
authors = ["Lewin Bormann <lewin@lewin-bormann.info>"]
edition = "2018"
[dependencies]
yup-oauth2 = { path = "../../" }
hyper = "0.12"
hyper-tls = "0.3"
futures = "0.1"
tokio = "0.1"

View File

@@ -0,0 +1,26 @@
use futures::prelude::*;
use yup_oauth2;
use hyper::client::Client;
use hyper_tls::HttpsConnector;
use std::path;
use tokio;
fn main() {
let creds = yup_oauth2::read_application_secret(path::Path::new("clientsecret.json"))
.expect("clientsecret");
let https = HttpsConnector::new(1).expect("tls");
let client = Client::builder().build::<_, hyper::Body>(https);
let scopes = &["https://www.googleapis.com/auth/youtube.readonly".to_string()];
let ad = yup_oauth2::DefaultAuthenticatorDelegate;
let mut df = yup_oauth2::DeviceFlow::new::<String>(client, creds, ad, None);
let mut rt = tokio::runtime::Runtime::new().unwrap();
let fut = df
.retrieve_device_token(scopes.to_vec())
.and_then(|tok| Ok(println!("{:?}", tok)));
rt.block_on(fut).unwrap()
}