aboutsummaryrefslogtreecommitdiffstats
path: root/teleterm/src/web/oauth.rs
blob: 59f60e184961600638d1934d5fd6ded6486b53ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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(),
    )
}