inth-oauth2/examples/google-installed.rs

30 lines
861 B
Rust
Raw Normal View History

2015-12-22 03:53:45 +00:00
extern crate inth_oauth2;
2015-12-24 06:11:14 +00:00
use std::io;
2015-12-26 01:23:48 +00:00
use inth_oauth2::Client;
use inth_oauth2::provider::google::Installed;
2015-12-22 03:53:45 +00:00
fn main() {
let client = Client::<Installed>::new(
2016-01-29 02:54:14 +00:00
String::from("143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com"),
String::from("3kZ5WomzHFlN2f_XbhkyPd3o"),
Some(String::from("urn:ietf:wg:oauth:2.0: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();
let http_client = Default::default();
let token = client.request_token(&http_client, code.trim()).unwrap();
2015-12-24 06:11:14 +00:00
println!("{:?}", token);
2015-12-24 19:38:00 +00:00
let token = client.refresh_token(&http_client, token, None).unwrap();
2015-12-24 19:38:00 +00:00
println!("{:?}", token);
2015-12-22 03:53:45 +00:00
}