aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDankDumpster <[email protected]>2021-01-14 08:19:30 +0100
committerDankDumpster <[email protected]>2021-01-14 08:19:30 +0100
commitec7b0fbcd2f3273d51e15c5c1b34b45cb5a4f46f (patch)
treed407e0ee19ce0551a558f6e757b613783ef06067 /examples
parentInitial commit (diff)
downloadoauth-ec7b0fbcd2f3273d51e15c5c1b34b45cb5a4f46f.tar.xz
oauth-ec7b0fbcd2f3273d51e15c5c1b34b45cb5a4f46f.zip
added reqwest support
Diffstat (limited to 'examples')
-rw-r--r--examples/rocket.rs39
1 files changed, 15 insertions, 24 deletions
diff --git a/examples/rocket.rs b/examples/rocket.rs
index d661e2f..13050ce 100644
--- a/examples/rocket.rs
+++ b/examples/rocket.rs
@@ -19,21 +19,14 @@
//! `$ git clone https://github.com/serenity-rs/oauth`
//! `$ cd oauth`
//! `$ DISCORD_CLIENT_SECRET=my_secret DISCORD_CLIENT_ID=my_client_id cargo run --example rocket`
+#![feature(decl_macro)]
-#![feature(custom_derive, plugin)]
-#![plugin(rocket_codegen)]
-
-extern crate hyper;
-extern crate hyper_native_tls;
-extern crate serenity_oauth;
+#[macro_use]
extern crate rocket;
-use hyper::net::HttpsConnector;
-use hyper::Client as HyperClient;
-use hyper_native_tls::NativeTlsClient;
use rocket::response::Redirect;
use serenity_oauth::model::AccessTokenExchangeRequest;
-use serenity_oauth::{DiscordOAuthHyperRequester, Scope};
+use serenity_oauth::{DiscordOAuthReqwestRequester, Scope};
use std::env;
use std::error::Error;
@@ -50,25 +43,25 @@ fn get_client_id() -> u64 {
}
fn get_client_secret() -> String {
- env::var("DISCORD_CLIENT_SECRET")
- .expect("No DISCORD_CLIENT_SECRET present")
+ env::var("DISCORD_CLIENT_SECRET").expect("No DISCORD_CLIENT_SECRET present")
}
-#[get("/callback?<params>")]
-fn get_callback(params: Params) -> Result<String, Box<Error>> {
+#[get("/callback?<code>")]
+fn get_callback(code: String) -> Result<String, Box<dyn Error>> {
// Exchange the code for an access token.
- let ssl = NativeTlsClient::new()?;
- let connector = HttpsConnector::new(ssl);
- let client = HyperClient::with_connector(connector);
+ let client = reqwest::blocking::Client::new();
let response = client.exchange_code(&AccessTokenExchangeRequest::new(
get_client_id(),
get_client_secret(),
- params.code,
+ code,
"http://localhost:8000/callback",
))?;
- Ok(format!("The user's access token is: {}", response.access_token))
+ Ok(format!(
+ "The user's access token is: {}",
+ response.access_token
+ ))
}
#[get("/")]
@@ -82,13 +75,11 @@ fn get_redirect() -> Redirect {
"http://localhost:8000/callback",
);
- Redirect::to(&url)
+ Redirect::to(url)
}
fn main() {
rocket::ignite()
- .mount("/", routes![
- get_callback,
- get_redirect,
- ]).launch();
+ .mount("/", routes![get_callback, get_redirect,])
+ .launch();
}