1use std::collections::HashMap;
8
9#[derive(Debug, Clone, Default)]
11pub struct Claims {
12 pub sub: String,
13 pub email: String,
14 pub role: String,
15 pub roles: Vec<String>,
16 pub mfa: String,
19}
20
21#[derive(Debug, Clone, Default)]
22pub struct ReqCtx {
23 pub query: String,
25 pub mount: String,
27 pub path_params: HashMap<String, String>,
28 pub headers: HashMap<String, String>,
29 pub claims: Option<Claims>,
30 pub csrf: Option<String>,
33}
34
35impl ReqCtx {
36 pub fn new() -> Self {
37 Self::default()
38 }
39
40 pub fn with_query(mut self, query: impl Into<String>) -> Self {
41 self.query = query.into();
42 self
43 }
44
45 pub fn with_mount(mut self, mount: impl Into<String>) -> Self {
46 self.mount = mount.into();
47 self
48 }
49
50 pub fn with_claims(mut self, claims: Claims) -> Self {
51 self.claims = Some(claims);
52 self
53 }
54
55 pub fn with_csrf(mut self, csrf: impl Into<String>) -> Self {
56 self.csrf = Some(csrf.into());
57 self
58 }
59
60 pub fn roles(&self) -> Vec<String> {
62 match &self.claims {
63 Some(c) => {
64 let mut r = c.roles.clone();
65 if !c.role.is_empty() && !r.contains(&c.role) {
66 r.push(c.role.clone());
67 }
68 r
69 }
70 None => Vec::new(),
71 }
72 }
73}