From 23911b9ad5d942456fc2b4a517c5cf6c67e0a611 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 27 Nov 2019 12:48:24 -0500 Subject: add oauth endpoint no functionality yet --- teleterm/src/web.rs | 6 +++++ teleterm/src/web/oauth.rs | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 teleterm/src/web/oauth.rs diff --git a/teleterm/src/web.rs b/teleterm/src/web.rs index 48c8c3c..c1e954c 100644 --- a/teleterm/src/web.rs +++ b/teleterm/src/web.rs @@ -2,6 +2,7 @@ mod disk_session; mod list; mod login; mod logout; +mod oauth; mod view; mod watch; mod ws; @@ -158,6 +159,11 @@ fn router(data: &Config) -> impl gotham::handler::NewHandler { .get("/login") .with_query_string_extractor::() .to(login::run); + route + .get("/oauth/:method") + .with_path_extractor::() + .with_query_string_extractor::() + .to(oauth::run); route.get("/logout").to(logout::run); }) } diff --git a/teleterm/src/web/oauth.rs b/teleterm/src/web/oauth.rs new file mode 100644 index 0000000..59f60e1 --- /dev/null +++ b/teleterm/src/web/oauth.rs @@ -0,0 +1,56 @@ +use gotham::state::FromState as _; +use std::convert::TryFrom as _; + +#[derive( + serde::Deserialize, + gotham_derive::StateData, + gotham_derive::StaticResponseExtender, +)] +pub struct PathParts { + method: String, +} + +#[derive( + serde::Deserialize, + gotham_derive::StateData, + gotham_derive::StaticResponseExtender, +)] +pub struct QueryParams { + code: String, +} + +pub fn run( + mut state: gotham::state::State, +) -> (gotham::state::State, hyper::Response) { + let auth_type = { + let path_parts = PathParts::borrow_from(&state); + crate::protocol::AuthType::try_from(path_parts.method.as_str()) + }; + let auth_type = match auth_type { + Ok(auth_type) => auth_type, + Err(e) => { + return ( + state, + hyper::Response::builder() + .status(hyper::StatusCode::BAD_REQUEST) + .body(hyper::Body::from(format!("{}", e))) + .unwrap(), + ); + } + }; + let code = { + let query_params = QueryParams::borrow_from(&state); + query_params.code.clone() + }; + + // TODO + + ( + state, + hyper::Response::builder() + .status(hyper::StatusCode::FOUND) + .header(hyper::header::LOCATION, "/") + .body(hyper::Body::empty()) + .unwrap(), + ) +} -- cgit v1.2.3