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:
@@ -6,7 +6,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
yup-oauth2 = { path = "../../" }
|
||||
hyper = "0.12"
|
||||
hyper-rustls = "0.17"
|
||||
futures = "0.1"
|
||||
tokio = "0.1"
|
||||
hyper = {version = "0.13.0-alpha.4", features = ["unstable-stream"]}
|
||||
hyper-rustls = "=0.18.0-alpha.2"
|
||||
futures-preview = "=0.3.0-alpha.19"
|
||||
tokio = "=0.2.0-alpha.6"
|
||||
|
||||
@@ -1,24 +1,16 @@
|
||||
use futures::prelude::*;
|
||||
use yup_oauth2::GetToken;
|
||||
use yup_oauth2::{Authenticator, InstalledFlow};
|
||||
|
||||
use hyper::client::Client;
|
||||
use hyper_rustls::HttpsConnector;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let https = HttpsConnector::new(1);
|
||||
let client = Client::builder()
|
||||
.keep_alive(false)
|
||||
.build::<_, hyper::Body>(https);
|
||||
let ad = yup_oauth2::DefaultFlowDelegate;
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let secret = yup_oauth2::read_application_secret(Path::new("clientsecret.json"))
|
||||
.expect("clientsecret.json");
|
||||
|
||||
let mut auth = Authenticator::new(InstalledFlow::new(
|
||||
let auth = Authenticator::new(InstalledFlow::new(
|
||||
secret,
|
||||
yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect(8081),
|
||||
yup_oauth2::InstalledFlowReturnMethod::HTTPRedirectEphemeral,
|
||||
))
|
||||
.persist_tokens_to_disk("tokencache.json")
|
||||
.build()
|
||||
@@ -26,11 +18,8 @@ fn main() {
|
||||
let s = "https://www.googleapis.com/auth/drive.file".to_string();
|
||||
let scopes = vec![s];
|
||||
|
||||
let tok = auth.token(scopes);
|
||||
let fut = tok.map_err(|e| println!("error: {:?}", e)).and_then(|t| {
|
||||
println!("The token is {:?}", t);
|
||||
Ok(())
|
||||
});
|
||||
|
||||
tokio::run(fut)
|
||||
match auth.token(scopes).await {
|
||||
Err(e) => println!("error: {:?}", e),
|
||||
Ok(t) => println!("The token is {:?}", t),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user