diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-27 12:48:24 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-27 15:17:17 -0500 |
commit | 23911b9ad5d942456fc2b4a517c5cf6c67e0a611 (patch) | |
tree | 29a76423d36bb3269a596ec0564e755985f940b8 /teleterm/src/web/oauth.rs | |
parent | d26fe166b1f5fe2a5ea153a4d908598c61f4979b (diff) | |
download | teleterm-23911b9ad5d942456fc2b4a517c5cf6c67e0a611.tar.gz teleterm-23911b9ad5d942456fc2b4a517c5cf6c67e0a611.zip |
add oauth endpoint
no functionality yet
Diffstat (limited to 'teleterm/src/web/oauth.rs')
-rw-r--r-- | teleterm/src/web/oauth.rs | 56 |
1 files changed, 56 insertions, 0 deletions
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<hyper::Body>) { + 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(), + ) +} |