2017-06-05 00:05:30 +00:00
|
|
|
extern crate hyper;
|
|
|
|
extern crate hyper_native_tls;
|
2015-12-22 03:53:45 +00:00
|
|
|
extern crate inth_oauth2;
|
|
|
|
|
2015-12-24 06:11:14 +00:00
|
|
|
use std::io;
|
|
|
|
|
2017-06-05 00:05:30 +00:00
|
|
|
use hyper_native_tls::NativeTlsClient;
|
|
|
|
use hyper::net::HttpsConnector;
|
2015-12-26 01:23:48 +00:00
|
|
|
use inth_oauth2::Client;
|
2016-05-22 19:58:16 +00:00
|
|
|
use inth_oauth2::provider::google::{Installed, REDIRECT_URI_OOB};
|
2015-12-22 03:53:45 +00:00
|
|
|
|
|
|
|
fn main() {
|
2017-06-05 00:05:30 +00:00
|
|
|
let tls = NativeTlsClient::new().unwrap();
|
|
|
|
let connector = HttpsConnector::new(tls);
|
|
|
|
let https = hyper::Client::with_connector(connector);
|
|
|
|
|
2016-02-21 22:16:54 +00:00
|
|
|
let client = Client::<Installed>::new(
|
2016-01-29 02:54:14 +00:00
|
|
|
String::from("143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com"),
|
|
|
|
String::from("3kZ5WomzHFlN2f_XbhkyPd3o"),
|
2016-05-22 19:58:16 +00:00
|
|
|
Some(String::from(REDIRECT_URI_OOB)),
|
2015-12-22 03:53:45 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
let auth_uri = client.auth_uri(Some("https://www.googleapis.com/auth/userinfo.email"), None)
|
|
|
|
.unwrap();
|
|
|
|
println!("{}", auth_uri);
|
2015-12-24 06:11:14 +00:00
|
|
|
|
|
|
|
let mut code = String::new();
|
|
|
|
io::stdin().read_line(&mut code).unwrap();
|
|
|
|
|
2017-06-05 00:05:30 +00:00
|
|
|
let token = client.request_token(&https, code.trim()).unwrap();
|
2015-12-24 06:11:14 +00:00
|
|
|
println!("{:?}", token);
|
2015-12-24 19:38:00 +00:00
|
|
|
|
2017-06-05 00:05:30 +00:00
|
|
|
let token = client.refresh_token(&https, token, None).unwrap();
|
2015-12-24 19:38:00 +00:00
|
|
|
println!("{:?}", token);
|
2015-12-22 03:53:45 +00:00
|
|
|
}
|