summaryrefslogtreecommitdiffstats
path: root/crates/auth-service/src/server.rs
blob: 3433cd2ef58a32379df8c06c7ac9142cc14b133b (plain)
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
use axum::{Router, routing::get};
use tower_http::trace::TraceLayer;

use crate::{
    server::routes::{authorised::login_authorised, health_check},
    state::AppHandle,
};

pub mod csrf_token_validation;
pub mod keys;
pub mod grpc;
pub mod routes;

const CSRF_TOKEN: &str = "csrf_token";
const OAUTH_CSRF_COOKIE: &str = "SESSION";

pub fn router(state: AppHandle) -> Router {
    Router::new()
        .route("/auth/authorised", get(login_authorised))
        .route("/", get(health_check))
        .with_state(state.clone())
        .merge(routes::discord::discord_router(state))
        .layer(TraceLayer::new_for_http())
}

#[cfg(test)]
pub(crate) fn test_config() -> stack_up::Configuration {
    use stack_up::Configuration;

    let config_path = "auth.toml";

    let config = config::Config::builder()
        .add_source(config::File::new(config_path, config::FileFormat::Toml))
        .build()
        .unwrap();

    config.try_deserialize::<Configuration>().unwrap()
}