mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-02-23 15:50:00 +01:00
refactor(DeviceFlow): Make DeviceFlow work with Futures
This commit is contained in:
12
examples/test-device/Cargo.toml
Normal file
12
examples/test-device/Cargo.toml
Normal 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"
|
||||
26
examples/test-device/src/main.rs
Normal file
26
examples/test-device/src/main.rs
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user