use std::collections::HashMap;
#[derive(Debug, Clone, Default)]
pub struct Claims {
pub sub: String,
pub email: String,
pub role: String,
pub roles: Vec<String>,
pub mfa: String,
}
#[derive(Debug, Clone, Default)]
pub struct ReqCtx {
pub query: String,
pub mount: String,
pub path_params: HashMap<String, String>,
pub headers: HashMap<String, String>,
pub claims: Option<Claims>,
pub csrf: Option<String>,
}
impl ReqCtx {
pub fn new() -> Self {
Self::default()
}
pub fn with_query(mut self, query: impl Into<String>) -> Self {
self.query = query.into();
self
}
pub fn with_mount(mut self, mount: impl Into<String>) -> Self {
self.mount = mount.into();
self
}
pub fn with_claims(mut self, claims: Claims) -> Self {
self.claims = Some(claims);
self
}
pub fn with_csrf(mut self, csrf: impl Into<String>) -> Self {
self.csrf = Some(csrf.into());
self
}
pub fn roles(&self) -> Vec<String> {
match &self.claims {
Some(c) => {
let mut r = c.roles.clone();
if !c.role.is_empty() && !r.contains(&c.role) {
r.push(c.role.clone());
}
r
}
None => Vec::new(),
}
}
}