inth-oauth2/examples/google.rs

32 lines
744 B
Rust
Raw Normal View History

2015-11-28 08:36:13 +00:00
extern crate inth_oauth2;
2015-11-28 18:21:41 +00:00
use std::io;
2015-11-28 08:36:13 +00:00
use inth_oauth2::Client;
fn main() {
2015-11-28 09:14:12 +00:00
let client = Client::google(
2015-11-28 21:56:13 +00:00
Default::default(),
2015-11-28 09:14:12 +00:00
"143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com",
"3kZ5WomzHFlN2f_XbhkyPd3o",
Some("urn:ietf:wg:oauth:2.0:oob")
);
2015-11-28 08:36:13 +00:00
2015-11-28 09:14:12 +00:00
let auth_uri = client.auth_uri(
2015-11-28 08:36:13 +00:00
Some("https://www.googleapis.com/auth/userinfo.email"),
None
).unwrap();
println!("{}", auth_uri);
2015-11-28 18:21:41 +00:00
let mut code = String::new();
io::stdin().read_line(&mut code).unwrap();
2015-11-28 21:56:13 +00:00
let token = client.request_token(code.trim()).unwrap();
2015-11-28 20:21:16 +00:00
println!("{:?}", token);
2015-11-28 23:40:34 +00:00
let refreshed = client.refresh_token(&token, None).unwrap();
println!("{:?}", refreshed);
2015-11-28 08:36:13 +00:00
}