1
use std::collections::HashMap;
2

            
3
use axum::{http::Method, routing, Router};
4

            
5
use super::super::{
6
    oauth2::middleware::{AuthService, RoleScopeType},
7
    State,
8
};
9

            
10
mod api;
11
mod response;
12

            
13
974
pub fn new_service(scope_path: &str, state: &State) -> Router {
14
974
    let mut role_scopes_tokeninfo: HashMap<Method, RoleScopeType> = HashMap::new();
15
974
    let mut role_scopes_logout: HashMap<Method, RoleScopeType> = HashMap::new();
16
974

            
17
974
    match state.api_scopes.get("auth.tokeninfo.get") {
18
973
        None => {
19
973
            role_scopes_tokeninfo.insert(Method::GET, (vec![], vec![]));
20
973
        }
21
1
        Some(scopes) => {
22
1
            role_scopes_tokeninfo.insert(Method::GET, (vec![], scopes.clone()));
23
1
        }
24
    }
25
974
    match state.api_scopes.get("auth.logout.post") {
26
973
        None => {
27
973
            role_scopes_logout.insert(Method::POST, (vec![], vec![]));
28
973
        }
29
1
        Some(scopes) => {
30
1
            role_scopes_logout.insert(Method::POST, (vec![], scopes.clone()));
31
1
        }
32
    }
33

            
34
974
    Router::new().nest(
35
974
        scope_path,
36
974
        Router::new()
37
974
            .route(
38
974
                "/tokeninfo",
39
974
                routing::get(api::get_tokeninfo)
40
974
                    .layer(AuthService::new(&state.model, role_scopes_tokeninfo)),
41
974
            )
42
974
            .route(
43
974
                "/logout",
44
974
                routing::post(api::post_logout)
45
974
                    .layer(AuthService::new(&state.model, role_scopes_logout)),
46
974
            )
47
974
            .with_state(state.clone()),
48
974
    )
49
974
}