mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-02-23 15:50:00 +01:00
Move to std::futures to support async/await.
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
use futures::prelude::*;
|
||||
use yup_oauth2::{self, Authenticator, DeviceFlow, GetToken};
|
||||
|
||||
use std::path;
|
||||
use tokio;
|
||||
|
||||
fn main() {
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let creds = yup_oauth2::read_application_secret(path::Path::new("clientsecret.json"))
|
||||
.expect("clientsecret");
|
||||
let mut auth = Authenticator::new(DeviceFlow::new(creds))
|
||||
let auth = Authenticator::new(DeviceFlow::new(creds))
|
||||
.persist_tokens_to_disk("tokenstorage.json")
|
||||
.build()
|
||||
.expect("authenticator");
|
||||
|
||||
let scopes = vec!["https://www.googleapis.com/auth/youtube.readonly"];
|
||||
let mut rt = tokio::runtime::Runtime::new().unwrap();
|
||||
let fut = auth.token(scopes).and_then(|tok| Ok(println!("{:?}", tok)));
|
||||
|
||||
println!("{:?}", rt.block_on(fut));
|
||||
match auth.token(scopes).await {
|
||||
Err(e) => println!("error: {:?}", e),
|
||||
Ok(t) => println!("token: {:?}", t),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user