inth-oauth2/examples/github.rs

33 lines
896 B
Rust
Raw Normal View History

2017-06-05 00:05:30 +00:00
extern crate hyper;
extern crate hyper_native_tls;
2015-12-22 04:34:38 +00:00
extern crate inth_oauth2;
2015-12-24 19:44:06 +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;
2015-12-22 04:34:38 +00:00
use inth_oauth2::provider::GitHub;
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);
2017-08-23 18:09:05 +00:00
let client = Client::new(
GitHub,
2016-01-29 02:54:14 +00:00
String::from("01774654cd9a6051e478"),
String::from("9f14d16d95d605e715ec1a9aecec220d2565fd5c"),
2017-08-23 18:09:05 +00:00
Some(String::from("https://cmcenroe.me/oauth2-paste/")),
2015-12-22 04:34:38 +00:00
);
let auth_uri = client.auth_uri(Some("user"), None).unwrap();
println!("{}", auth_uri);
2015-12-24 19:44:06 +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 19:44:06 +00:00
println!("{:?}", token);
2015-12-22 04:34:38 +00:00
}